Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to encode cyrillic in mysql?

Tags:

php

mysql

what's up? :-)
I have one problem and i hope you can help me with it.

One friend of mine have a simple solid html website and i implemented little php; CRUD system for articles... problem i came across is placing and getting cyrillic characters from mysql database.

What i want to achive is next:
In the main navigation there are some separated sections, whose names, ids and item's order i want to place in mysql and than to pull names and to put each name as a link. Names are supposed to be cyrillic characters.

The problem comes when i, using php mysql_fetch_assoc function, try to display names which are inserted with cyrillic characters in database row, collation of row is utf8_general_ci, and i end with ????? insted of original characters. If i submit cyrillic characters via submit form to mysql it shows something like this У.

How can i solve this, thanks in advance!? :-)

like image 386
Premke Avatar asked Nov 26 '25 06:11

Premke


2 Answers

Make sure you call this after connecting to database.

mysql_query("SET NAMES UTF8");

Also make sure that HTML file has charset meta tag set to UTF-8 or send header before output.

header("Content-Type: text/html; charset=utf-8");
like image 174
Dejan Marjanović Avatar answered Nov 27 '25 20:11

Dejan Marjanović


I had the same problem until I encoded the 'Collation' column in my table to 'utf8_bin'.

like image 27
Frankie Avatar answered Nov 27 '25 22:11

Frankie



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!