Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node.js saving emojis to mysql as question marks

Tags:

node.js

mysql

I can store emojis with php pdo at same hosting - database. But i'm not able to do it with node js.

Im using code below for myqsl connettion with Node js. But when i tried to save text with emoji, emojis saving to database as quesiton mark.

 var con = mysql.createConnection({
    host: '127.0.0.1',
    port: 3306,
    user: 'db_user',
    password: 'db_password',
    database: 'db_name',
    charset: 'utf8mb4',
});


  con.connect(
    function (err) {
        if (err) {
            console.log("ERROR: ");
            throw err;
        } else {
            con.query('INSERT INTO messages (message_from, message_to,message) VALUES (?, ?, ?);', [message_from, message_to,message_text],
                function (err, results, fields) {
                    if (err) throw err;
                    else console.log('Inserted ' + results.affectedRows + ' row(s).');
                });
            con.end(
                function (err) {
                    if (err) throw err;
                });
        }
    });

i also tried

collation: "utf8mb4_general_ci",

but not working anyway.

Edit: Table and data type also utf8mb4

enter image description here

like image 805
Atakan Akbulut Avatar asked Sep 16 '25 01:09

Atakan Akbulut


1 Answers

I changed collation as comments says and it worked.

"utf8mb4_general_ci" to "utf8mb4_turkish_ci".

like image 115
Atakan Akbulut Avatar answered Sep 17 '25 17:09

Atakan Akbulut