Using Emoji in PHP MySQL
84   1  

Using Emoji in PHP MySQL

  14 Nov 2017
  Coding Category
Using Emoji in PHP MySQL

👉  Using Emoji in our website 🌐  dynamic messages 📝  is interesting and make our users happy 😃  🕺  💃  😃  We want to use them in MySQL with PHP, simple and short even if you have a DB and like to update it to use this feature. 💻  ⚙️  

1. We can add this feature to your DB, manually 💪  in PHPMyAdmin, with change Tables and Columns Collations to utf8mb4_unicode_ci and also use this code in config.php (that include in every pages):

mysqli_set_charset($db, "utf8mb4");

2. Now we run this code JUST ONCE 🤔  and then comment it to save time of server ⏳

$result = mysqli_query($db,'show tables');

while($tables = mysqli_fetch_array($result)) {

    foreach ($tables as $key => $value) {

        mysqli_query($db,"ALTER TABLE $value ENGINE = INNODB");

        mysqli_query($db,"ALTER TABLE $value COLLATE utf8mb4_unicode_ci");

        mysqli_query($db,"ALTER TABLE $value CONVERT TO CHARACTER SET utf8mb4");



mysqli_query($db,"ALTER DATABASE 'your_db' ENGINE = INNODB");

mysqli_query($db,"ALTER DATABASE 'your_db' COLLATE utf8mb4_unicode_ci");

mysqli_query($db,"ALTER DATABASE 'your_db' CONVERT TO CHARACTER SET utf8mb4");

 3. Remember this codes comes after connecting to DB like $db = mysqli_connect("DB_SERVER", "DB_USERNAME", "DB_PASSWORD", "DB_DATABASE"); 👍 👍  Have a nice time my dear friend 🌹

Author: Ismael Azaran

Do you like it? Share it with your friends.