Last active
October 5, 2021 20:15
-
-
Save battis/9e1b931a3199411e2a78 to your computer and use it in GitHub Desktop.
Trying to store/retrieve/display Unicode emoji in a MySQL database
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// MySQL schema | |
/* | |
CREATE TABLE `test` ( | |
`id` int(11) unsigned NOT NULL AUTO_INCREMENT, | |
`text` text, | |
`blob` blob, | |
PRIMARY KEY (`id`) | |
) ENGINE=InnoDB DEFAULT CHARSET=latin1; | |
*/ | |
// tell the browser we're going to be using Unicode characters | |
header('Content-type text/html; charset=UTF-8'); | |
$db = new mysqli('localhost', 'test', 'test', 'test'); | |
// http://stackoverflow.com/a/2446818/294171 -- makes no difference on my system | |
$db->query("SET character_set_client='utf8'"); | |
$db->query("SET character_set_results='utf8'"); | |
$db->query("set collation_connection='utf8_general_ci'"); | |
$statement = $db->prepare("INSERT INTO `test` (`text`) VALUES (?)"); | |
$emoji = '😀'; | |
$statement->bind_param('s', $emoji); | |
$statement->execute(); | |
echo "inserted $emoji"; | |
?> |
Thanks alot, what can be the reason for emojis to render black and white ❤️
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks you verrrry much 👍