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 join tables with PHP and MySQL?
- How to use a variable in a MySQL query using PHP?
- How to update to null value in MySQL using PHP?
- How to fetch data from MySQL in PHP?
- How to check if a record exists in PHP and MySQL?
- How to get the version of MySQL using PHP?
- How to escape a string for MySQL in PHP?
- How to convert MySQL datetime to string in PHP?
- How to export data from MySQL to Excel using PHP?
See more codes...