UTF-8 Cyrillic error - edited - mysql_real_escape_string
Moderator: General Moderators
UTF-8 Cyrillic error - edited - mysql_real_escape_string
Hi guys,
I have a simple HTML form and a MySQL db whose charset is utf-8 and collatio is utf_general_ci. My HTMK encoding is UTF-8(As it is said to be better than windows-1251). I send some text in Russian and I get an error. When I send send the same text with windows-1251 encoding of my web page it works.
The error I get is: 'Data too long for column 'answer' at row 1'.
Any ideas.
I do need to make it work with UTF-8 not with windows-1251.
I found where the problem comes from but another question raised. So the problem comes from mysql_real_escape_string(). When I remove it my code works as it is supposed to but else it does not.
Do you know why?
I have a simple HTML form and a MySQL db whose charset is utf-8 and collatio is utf_general_ci. My HTMK encoding is UTF-8(As it is said to be better than windows-1251). I send some text in Russian and I get an error. When I send send the same text with windows-1251 encoding of my web page it works.
The error I get is: 'Data too long for column 'answer' at row 1'.
Any ideas.
I do need to make it work with UTF-8 not with windows-1251.
I found where the problem comes from but another question raised. So the problem comes from mysql_real_escape_string(). When I remove it my code works as it is supposed to but else it does not.
Do you know why?
I strongly suggest to use mysql_real_escape_string().
Problem is that in database you have 'varchar' or 'char' type for column 'answer' with some size and you are trying to insert more data than column size.
To solve this You can increase size of the 'answer' column (still will have this problem with more data than expected) or change it to type 'text' (which i think is the better solution).
Problem is that in database you have 'varchar' or 'char' type for column 'answer' with some size and you are trying to insert more data than column size.
To solve this You can increase size of the 'answer' column (still will have this problem with more data than expected) or change it to type 'text' (which i think is the better solution).
- Ambush Commander
- DevNet Master
- Posts: 3698
- Joined: Mon Oct 25, 2004 9:29 pm
- Location: New Jersey, US
Rely
Ambush Commander: I do so with the only exception that I set it with utf8 but not with utf-8. I do so because I have read in mysql.com that I have to do it in that way. When I use utf-8 my insets and updates work but anything selected is '?'.
When I set the column type to blob it works but when I try to open it it seems that nothing has been saved.
It does not work with anything else.
Do you have any ideas?
When I set the column type to blob it works but when I try to open it it seems that nothing has been saved.
It does not work with anything else.
Do you have any ideas?
- Ambush Commander
- DevNet Master
- Posts: 3698
- Joined: Mon Oct 25, 2004 9:29 pm
- Location: New Jersey, US
Reply
Well, it is quite simple. I put the connection var in mysql_real_escape_string($str, $connection_var)l and it started working as it is supposed to. I use utf8 encoding, as I have already said.
BTW: After I fixed this I got another problem of the same kind but it was not with mysql_real_escape_string() but with htmlentities($str);. I set it in this way without the other parameters and I got an error. I fixed it by passing them.
I recommend anybody not to undertake parameters in parenthesis with Php functions.
BTW: After I fixed this I got another problem of the same kind but it was not with mysql_real_escape_string() but with htmlentities($str);. I set it in this way without the other parameters and I got an error. I fixed it by passing them.
I recommend anybody not to undertake parameters in parenthesis with Php functions.
Re: Reply
user___ wrote:Well, it is quite simple. I put the connection var in mysql_real_escape_string($str, $connection_var)l and it started working as it is supposed to. I use utf8 encoding, as I have already said.
BTW: After I fixed this I got another problem of the same kind but it was not with mysql_real_escape_string() but with htmlentities($str);. I set it in this way without the other parameters and I got an error. I fixed it by passing them.
I recommend anybody not to undertake parameters in parenthesis with Php functions.
Glad you made it.
By the way if you have only one connection and mysql_real_escape_string does not get the correct encoding...without explicitly passing $connection_var I think this should be considered a php bug. As stated in PHP manual...if not passed ...last connection opened with mysql_query will be used...apperantly in your case it was used...but encoding lost somehow.