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 use a variable in a MySQL query using PHP?
- How to check the result of an insert in PHP and MySQL?
- How to get the version of MySQL using PHP?
- How to fetch data from MySQL in PHP?
- How to get a single value from query in PHP MySQL?
- How to get the first row of a result in MySQL using PHP?
- How to update to null value in MySQL using PHP?
- How to use a MySQL union in PHP?
- How to generate a UUID in MySQL using PHP?
See more codes...