php-mysqlHow to insert an emoji into MySQL table in PHP?
To insert an emoji into a MySQL table in PHP, you can use the mysqli_real_escape_string()
function. This function takes a string as an argument and returns a string with special characters escaped.
Example code
$emoji = "😃";
$escaped_emoji = mysqli_real_escape_string($conn, $emoji);
$sql = "INSERT INTO table_name (emoji_column) VALUES ('$escaped_emoji')";
The code above will insert the emoji into the table_name
table in the emoji_column
column.
Code explanation
$emoji
: a variable containing the emoji to be insertedmysqli_real_escape_string($conn, $emoji)
: a function that takes a connection and a string as arguments and returns a string with special characters escaped$sql
: a variable containing the SQL query to insert the emoji into the table
Helpful links
More of Php Mysql
- How to use utf8mb4_unicode_ci in MySQL with PHP?
- How to join tables with PHP and MySQL?
- How to get the version of MySQL using PHP?
- How to write an update query in MySQL using PHP?
- How to count the number of resulting rows in a MySQL database using PHP?
- How to use a MySQL union in PHP?
- How to set a timeout for MySQL query in PHP?
- How to create an SSL connection to MySQL using PHP?
- How to get the last insert ID in PHP MySQL?
- How to fetch data from MySQL in PHP?
See more codes...