1

I have a PHP code and node js code that saves and get some info to/from MySQL database. Some data is in foreign language. All encoding (Database, tables, fields) is set to utf8.
If I send something like "якийсь текст" to database via PHP, in database it will look like "ÑкийÑÑŒ текÑÑ‚" and if I retrieve this text from database with PHP I get "якийсь текст" which is fine.
But when I sent same text to db with node, in db it will be saved as it is(якийсь текст) but when retrieving it from the db with PHP - I am getting just question marks. In node mysql.createConnection I have set charset: 'utf8' and added conc.query("SET NAMES utf8") .
So I am not sure what I am doing wrong.
Thanks

user3195616
  • 195
  • 2
  • 13
  • Where are you seeing the question marks? In the client? If so try this - https://stackoverflow.com/questions/17872789/node-js-express-how-do-i-set-response-character-encoding – Evan Shortiss Jul 17 '18 at 00:40

1 Answers1

-1

That's Mojibake. See this for causes.

That also discusses "question marks".

Since you have two symptoms, I suggest you have at least two coding errors. So, see "Best Practice" in that link, too.

Show us:

  • The connection string
  • SHOW CREATE TABLE
  • SELECT HEX(col), col FROM tbl WHERE ...

It could be "double encoding" -- which is insidious in that it looks ok except when you compare strings.

UTF-8 як is hex D18F D0BA. However, if doubly encoded, you get C391 C28F C390 C2BA

The SET NAMES utf8 should have helped; but that is only one of about 5 things that need to match.

node.js needs something like

var connection = mysql.createConnection({ ... , charset : 'utf8'});

(or utf8mb4)

Rick James
  • 135,179
  • 13
  • 127
  • 222