php-mysqlHow to use utf8mb4_unicode_ci in MySQL with PHP?
MySQL supports the utf8mb4_unicode_ci character set, which allows for storing characters from a wide range of languages. To use this character set in PHP, you need to set the character set in the connection string when connecting to the database.
$conn = new mysqli("localhost", "username", "password", "database", 3306, "", MYSQLI_CLIENT_SSL);
$conn->set_charset("utf8mb4_unicode_ci");
The code above creates a new connection to the database and sets the character set to utf8mb4_unicode_ci.
Code explanation
$conn = new mysqli("localhost", "username", "password", "database", 3306, "", MYSQLI_CLIENT_SSL);
- creates a new connection to the database.$conn->set_charset("utf8mb4_unicode_ci");
- sets the character set to utf8mb4_unicode_ci.
Helpful links
More of Php Mysql
- How to order by a column in ascending order in MySQL using PHP?
- How to get the version of MySQL using PHP?
- How to count the number of resulting rows in a MySQL database using PHP?
- How to set a timeout for MySQL query in PHP?
- How to insert a null value in MySQL using PHP?
- How to get a single value from query in PHP MySQL?
- How to use a MySQL union in PHP?
- How to change database in MySQL with PHP?
- How to store a boolean value in a MySQL database using PHP?
See more codes...