Data Storage and Access

suggest change
This topic specifically talks about UTF-8 and considerations for using it with a database. If you want more information about using databases in PHP then checkout this topic.

Storing Data in a MySQL Database:

MySQL will implicitly use utf8mb4 encoding if a utf8mb4_* collation is specified (without any explicit character set).

Accessing Data in a MySQL Database:

For Example (The same consideration regarding utf8mb4/utf8 applies as above):

- If you're using the [PDO][1] abstraction layer with PHP ≥ 5.3.6, you can specify `charset` in the [DSN][2]:

      $handle = new PDO('mysql:charset=utf8mb4');

- If you're using [mysqli][3], you can call [`set_charset()`][4]:

      $conn = mysqli_connect('localhost', 'my_user', 'my_password', 'my_db');

      $conn->set_charset('utf8mb4');        // object oriented style
      mysqli_set_charset($conn, 'utf8mb4'); // procedural style

- If you're stuck with plain [mysql][5] but happen to be running PHP ≥ 5.2.3, you can call [`mysql_set_charset`][6].

      $conn = mysql_connect('localhost', 'my_user', 'my_password');

      $conn->set_charset('utf8mb4');       // object oriented style
      mysql_set_charset($conn, 'utf8mb4'); // procedural style

- If the database driver does not provide its own mechanism for setting the connection character set, you may have to issue a query to tell MySQL how your application expects data on the connection to be encoded: [`SET NAMES 'utf8mb4'`][7].

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:


UTF-8:
* UTF-8
* Input
* Output
* Data Storage and Access

Table Of Contents
2 Arrays
4 Types
10 Cookies
14 JSON
15 SOAP
17 cURL
19 XML
21 Traits
35 UTF-8
36 URLs
38 PHPDoc
41 Loops
44 Closur
72 YAML
77 Cache
78 Streams
81 PDO
82 SQLite3
83 Sockets
87 MongoDB
93 IMAP
94 Redis
95 Imagick
102 APCu
108 PSR