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 get the version of MySQL using PHP?
- How to output XML from MySQL using PHP?
- How to update to null value in MySQL using PHP?
- How to use a variable in a MySQL query using PHP?
- How to create an SSL connection to MySQL using PHP?
- How to set a timeout for MySQL query in PHP?
- How to export data from MySQL to Excel using PHP?
- How to get the error message for a MySQL query using PHP?
- How to use a MySQL union in PHP?
See more codes...