vaneayoung
vaneayoung

Reputation: 363

What is the best charset encoding for sql query?

I tried with mysqli_set_charset("cp1251") and with utf8, not working.

I've tryed to insert string in sql like this htmlentities($str, ENT_QUOTES, "UTF-8"); and for accent letters working perfectly but for russian characters the result is like this Øóôóòèíñêèé Ìèõàèë.

Thanks.

Upvotes: 0

Views: 1032

Answers (1)

Izzet Beltir
Izzet Beltir

Reputation: 126

It is important to use the same character set in the complete data chain. Mixed encodings will always cause problems.

  • Set the table or column encoding to charset x
  • Set the database connection encoding to charset x
  • Set the internal encoding of PHP to charset x or convert the string
  • Set the input and output client (mysql console, browser or cli) encoding to charset x
  • When you are using a browser check the encoding which is set in the http header, too. Depending on the browser this value might overwrite an exisiting meta tag in the html header!

Upvotes: 2

Related Questions