Jump to content

still charset troubles cp1251


ervan

Recommended Posts

First of all, hello y'all. I'm newbie in web developnent, and i got pure english so sorry for that.

 

Becouse i'm russian (well almost russian, exUSSR anyway) so, i need to use cp1251 charset by default in my base. I read ton of articles (in russian and english, the most useful is http://dev.mysql.com/doc/refman/5.0/en/charset-connection.html), but still have a questions.

 

I downloaded and installed MySql 5.0 + php 5 + apache 2.2 on my local windows machine. When I install mysql (russian version) it promter for charset, I, of course, selected cp1251. Then mysql.exe don't started becouse of path problem, then i typed in my.ini:

 

character-sets-dir="<mysql_proper_path>/MySQL/share/charsets"

 

This problem, solves quickly, by default there(my.ini) is some lines according to charset:

 

default-character-set=cp1251

 

Some manuals advance to set

 

init-connect="SET NAMES cp1251"

but when i typed thet, mysql.exe says:

 

mysql: unknown variable 'init-connect=SET NAMES cp1251'

 

First question is why ? So i skipped that advice;

When i firts run mysql.exe and typed:

SHOW VARIABLES LIKE 'character_set%';

i got:

+--------------------------+---------------------------------------+
| Variable_name            | Value                                 |
+--------------------------+---------------------------------------+
| character_set_client     | cp1251                                |
| character_set_connection | cp1251                                |
| character_set_database   | cp1251                                |
| character_set_filesystem | binary                                |
| character_set_results    | cp1251                                |
| character_set_server     | cp1251                                |
| character_set_system     | utf8                                  |
| character_sets_dir       | D:\mustdie\prog\MySQL\share\charsets\ |
+--------------------------+---------------------------------------+

seems all ok. I createded database, tables and added some data in my native langauge(all using mysql.exe). But when i tryed to access that data from php script, i got unreadable text :(

First i write that script to see character_set* variables:

...
	$res = mysql_query("SHOW VARIABLES LIKE 'character_set%';");

	$rows = mysql_num_rows($res);

	echo "rows = $rows<br>";
	while ($rows > 0)
	{
		$fields = mysql_fetch_array($res);

		$num = mysql_num_fields($res);

		$i = 0;
		while($i < $num)
		{
			echo "$fields[$i] ";
			$i++;
		}
		echo "<br>";
		$rows--;
	};
...

and i got ^_^:

rows = 8
character_set_client latin1 
character_set_connection latin1 
character_set_database cp1251 
character_set_filesystem binary 
character_set_results latin1 
character_set_server cp1251 
character_set_system utf8 
character_sets_dir D:\mustdie\prog\MySQL\share\charsets\

Second question is why in php script i got different variables that from mysql.exe (i runned mysql.exe with parameters: C:\<path>>mysql.exe -u root -p)?

OK, I typed before  that script

mysql_query("set names cp1251;")

and results from mysql.exe and php script were the same.

 

seems all ok, but when I tryed add some data from php script to database like that:

	$name = "\"руссиш текст\"";
$data = "\"давай выпьем\"";
$query = "insert into posts (name, data, date, time) values ($name, $data, CURRENT_DATE(), CURRENT_TIME());";

that text data was unreadable from mysql.exe intepreter :( and text data that i added manualy from interpreter were unreadable from php scripts. So this is the main question. What should I do to see readable data from interpreter and php script?

 

note that there is no problem with source file encoding, files has cyrillic encoding.

if u want, u cant contact to me fast via icq: 477-844-980

 

thanks y'all, anyway %)

cheers, rain

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.