This is a discussion on Mysql database in UTF8, PHP shows latin1 (iso-8859-1) within the MySQL forums, part of the Database Server Software category; --> >>> character_set_client=latin1 >> That is a problem I also had. the [mysql] section of my.cnf is for the >> ...
| |||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| >>> character_set_client=latin1 >> That is a problem I also had. the [mysql] section of my.cnf is for the >> command-line client only. A [client] section may or may not be used for >> PHP connections. I had to send a "SET NAMES utf8" upon connection to >> really convince MySQL to use utf8 for the connection. > > That's how it's supposed to be and was already mentioned multiple times. > How else should MySQL know what connection encoding the PHP client and > your scripts prefer? You should either be able to configure it reliably OR have a default encoding. The way it is now, this is not the case. If you send an SQL file through the command-line client, the default encoding can be DIFFERENT from the situation where you send the exact same file through PHP. That is the problem here. The whole command "SET NAMES utf8" is not even legible if the encoding is set to ucs-2. That is why that encoding is not possible in MySQL. Off course, the default encoding should be passed in the connection. Can you tell me what the default encoding is when connecting? According to the manual, any "language character" can be used to use for a database name. So mysql_select_db() will not use latin-1, as you would not be able to refer to your database. Or is it? I could not find it anywhere. > >> This really sucks, off course. It is plain stupid to have to set the >> encoding used encoded in the encoding it has to set. It is like sending >> a key INSIDE a safe which requires that key to open it. > > You connect to the DB using the default encoding and then set it to > whatever you want it to be. There's nothing stupid about that. > > Micha The problem with that, off course, is that this is highly vendor, version AND client-specific. The command-line client behaves differently than a PHP initiated connection if you do not send it. Now that was the exact problem of the original poster. And older database versions do not even understand it. Best regards, -- Willem Bogaerts Application smith Kratz B.V. http://www.kratz.nl/ |
| |||
| On Tue, 08 Apr 2008 12:57:29 +0200, Willem Bogaerts wrote: >>>> character_set_client=latin1 >>> That is a problem I also had. the [mysql] section of my.cnf is for the >>> command-line client only. A [client] section may or may not be used for >>> PHP connections. I had to send a "SET NAMES utf8" upon connection to >>> really convince MySQL to use utf8 for the connection. >> >> That's how it's supposed to be and was already mentioned multiple times. >> How else should MySQL know what connection encoding the PHP client and >> your scripts prefer? > > You should either be able to configure it reliably OR have a default > encoding. The way it is now, this is not the case. If you send an SQL > file through the command-line client, the default encoding can be > DIFFERENT from the situation where you send the exact same file through > PHP. That is the problem here. The whole command "SET NAMES utf8" is not > even legible if the encoding is set to ucs-2. That is why that > encoding is not possible in MySQL. Don't be silly. ucs2, utf16 and utf32 cannot be used for SET NAMES or SET CHARACTER SET. It's in the manual, in the section about connection charsets. You DID read that section, didn't you, before complaining that connection charsets make no sense? > Off course, the default encoding should be passed in the connection. > Can you tell me what the default encoding is when connecting? > According to the manual, any "language character" can be used to use > for a database name. So mysql_select_db() will not use latin-1, as you > would not be able to refer to your database. Or is it? I could not > find it anywhere. It's whatever you use on the --default-character-set=charset_name option, or in the my.cnf file, or latin-1, in that order. This is a lot less hard if you try reading and knowing the documentation that accompanies your installation. >>> This really sucks, off course. It is plain stupid to have to set >>> the encoding used encoded in the encoding it has to set. It is like >>> sending a key INSIDE a safe which requires that key to open it. >> >> You connect to the DB using the default encoding and then set it to >> whatever you want it to be. There's nothing stupid about that. >> >> Micha > > The problem with that, off course, is that this is highly vendor, > version AND client-specific. The command-line client behaves > differently than a PHP initiated connection if you do not send it. That's why you send it, whenever you are unsure of what it is currently set to. This is as ridiculous as complaining about having to explicitly open a connection to mysql in PHP as well, and feeling hurt that you have to specify which database you want to use. "Why not have a sensible default database and just use that?!?" > Now that was the exact problem of the original poster. And older > database versions do not even understand it. How old a database do you HAVE? The first note on the connection charset page in the online manual is from 2004. -- The Web brings people together because no matter what kind of a twisted sexual mutant you happen to be, you've got millions of pals out there. Type in 'Find people that have sex with goats that are on fire' and the computer will ask, 'Specify type of goat.' -- Rich Jeni |
| |||
| alex schrieb: > > I made a simple script in PHP to dump data from tables which had non > standard characters. But the resulting page is viewed correctly in > iso-8859-1 encoding and not in UTF-8. > > At this moment i'm clueless were the problem lies. Hello, well, first of all, I'm newbie with MYSQL & Co., I have read all answers and followed the link reading them all carefully. I suppose I understand the matter. I have apparently the same problem as Alex has. But my connection is in UTF-8 and I need ISO-8859-1. The problem accrued as I've moved from my webspace to a vServer. The old configuration shown by phpMyAdmin on MySQL 4.1.13 is: character set client utf8 (Globaler Wert) latin1 character set connection utf8 (Globaler Wert) latin1 character set database latin1 character set results utf8 (Globaler Wert) latin1 character set server latin1 character set system utf8 collation connection utf8_general_ci (Globaler Wert) latin1_swedish_ci collation database latin1_swedish_ci collation server latin1_swedish_ci The new configuration shown by phpMyAdmin on my new MySQL 5.0.32 is exactly the same, the I set "SET NAMES latin1" via mysql-shell. BUT: Making "SHOW VARIABLES" at mysql-shell gives: character_set_client latin1 character_set_connection latin1 character_set_database latin1 character_set_filesystem binary character set results latin1 character set server latin1 character set system utf8 collation connection latin1_swedish_ci collation database latin1_swedish_ci collation server latin1_swedish_ci asking for the values by PHP gives: character_set_client utf8 character_set_connection utf8 character_set_database latin1 character_set_filesystem binary character_set_results utf8 character_set_server latin1 character_set_system utf8 collation_connection utf8_general_ci collation_database latin1_swedish_ci collation_server latin1_swedish_ci I need the character_set_client and character_set_connection in latin1. The HTTP header sends to the browser ISO-8859-15. That should stay so, because about 2.000 html pages are coded in this. I don't care for the DB contect, then I have it local in some programm. My only wish is to establish a working-encoding-connection between the PHP and DB. Can You please tell what exactly I have to do? Please, understand I can't reprogramm the application, I even don't want to, because it worked before. I'm quit sure it's not correct setted up. Thanks a lot in advance!!! Regards Marc |
| |||
| Marc wrote: > alex schrieb: >> >> I made a simple script in PHP to dump data from tables which had non >> standard characters. But the resulting page is viewed correctly in >> iso-8859-1 encoding and not in UTF-8. >> >> At this moment i'm clueless were the problem lies. > > Hello, > > well, first of all, I'm newbie with MYSQL & Co., I have read all answers > and followed the link reading them all carefully. I suppose I understand > the matter. > > I have apparently the same problem as Alex has. But my connection is in > UTF-8 and I need ISO-8859-1. > > The problem accrued as I've moved from my webspace to a vServer. > > The old configuration shown by phpMyAdmin on MySQL 4.1.13 is: > > character set client utf8 > (Globaler Wert) latin1 > character set connection utf8 > (Globaler Wert) latin1 > character set database latin1 > character set results utf8 > (Globaler Wert) latin1 > character set server latin1 > character set system utf8 > collation connection utf8_general_ci > (Globaler Wert) latin1_swedish_ci > collation database latin1_swedish_ci > collation server latin1_swedish_ci > > The new configuration shown by phpMyAdmin on my new MySQL 5.0.32 is > exactly the same, the I set "SET NAMES latin1" via mysql-shell. > > BUT: > > Making "SHOW VARIABLES" at mysql-shell gives: > > character_set_client latin1 > character_set_connection latin1 > character_set_database latin1 > character_set_filesystem binary > character set results latin1 > character set server latin1 > character set system utf8 > collation connection latin1_swedish_ci > collation database latin1_swedish_ci > collation server latin1_swedish_ci > > asking for the values by PHP gives: > > character_set_client utf8 > character_set_connection utf8 > character_set_database latin1 > character_set_filesystem binary > character_set_results utf8 > character_set_server latin1 > character_set_system utf8 > collation_connection utf8_general_ci > collation_database latin1_swedish_ci > collation_server latin1_swedish_ci > > I need the character_set_client and character_set_connection in latin1. > > The HTTP header sends to the browser ISO-8859-15. That should stay so, > because about 2.000 html pages are coded in this. I don't care for the > DB contect, then I have it local in some programm. My only wish is to > establish a working-encoding-connection between the PHP and DB. > > Can You please tell what exactly I have to do? Please, understand I > can't reprogramm the application, I even don't want to, because it > worked before. I'm quit sure it's not correct setted up. > > Thanks a lot in advance!!! > > Regards > > Marc > Marc, Look at the differences in your settings. Then look at the fact these are MySQL settings, not PHP. And look at the questions you're asking - about the character set in the connection and client. These are all MySQL items - which should be a clue that you should be asking in comp.databases.mysql, not here. -- ================== Remove the "x" from my email address Jerry Stuckle JDS Computer Training Corp. jstucklex@attglobal.net ================== |
| |||
| Marc wrote: > alex schrieb: >> >> I made a simple script in PHP to dump data from tables which had non >> standard characters. But the resulting page is viewed correctly in >> iso-8859-1 encoding and not in UTF-8. >> >> At this moment i'm clueless were the problem lies. > > Hello, > > well, first of all, I'm newbie with MYSQL & Co., I have read all answers > and followed the link reading them all carefully. I suppose I understand > the matter. > > I have apparently the same problem as Alex has. But my connection is in > UTF-8 and I need ISO-8859-1. > > The problem accrued as I've moved from my webspace to a vServer. > > The old configuration shown by phpMyAdmin on MySQL 4.1.13 is: > > character set client utf8 > (Globaler Wert) latin1 > character set connection utf8 > (Globaler Wert) latin1 > character set database latin1 > character set results utf8 > (Globaler Wert) latin1 > character set server latin1 > character set system utf8 > collation connection utf8_general_ci > (Globaler Wert) latin1_swedish_ci > collation database latin1_swedish_ci > collation server latin1_swedish_ci > > The new configuration shown by phpMyAdmin on my new MySQL 5.0.32 is > exactly the same, the I set "SET NAMES latin1" via mysql-shell. > > BUT: > > Making "SHOW VARIABLES" at mysql-shell gives: > > character_set_client latin1 > character_set_connection latin1 > character_set_database latin1 > character_set_filesystem binary > character set results latin1 > character set server latin1 > character set system utf8 > collation connection latin1_swedish_ci > collation database latin1_swedish_ci > collation server latin1_swedish_ci > > asking for the values by PHP gives: > > character_set_client utf8 > character_set_connection utf8 > character_set_database latin1 > character_set_filesystem binary > character_set_results utf8 > character_set_server latin1 > character_set_system utf8 > collation_connection utf8_general_ci > collation_database latin1_swedish_ci > collation_server latin1_swedish_ci > > I need the character_set_client and character_set_connection in latin1. > > The HTTP header sends to the browser ISO-8859-15. That should stay so, > because about 2.000 html pages are coded in this. I don't care for the > DB contect, then I have it local in some programm. My only wish is to > establish a working-encoding-connection between the PHP and DB. > > Can You please tell what exactly I have to do? Please, understand I > can't reprogramm the application, I even don't want to, because it > worked before. I'm quit sure it's not correct setted up. > > Thanks a lot in advance!!! > > Regards > > Marc > Oops, I didn't notice you crossposted this to comp.databases.mysql. You indicated you had "non-standard" characters in the database. The first question is - what charset is the data in the database in? And exactly what are these "non-standard" characters? -- ================== Remove the "x" from my email address Jerry Stuckle JDS Computer Training Corp. jstucklex@attglobal.net ================== |
| |||
| Greetings, Marc. In reply to Your message dated Sunday, June 8, 2008, 23:06:35, >> I made a simple script in PHP to dump data from tables which had non >> standard characters. But the resulting page is viewed correctly in >> iso-8859-1 encoding and not in UTF-8. >> >> At this moment i'm clueless were the problem lies. > Hello, > well, first of all, I'm newbie with MYSQL & Co., I have read all answers > and followed the link reading them all carefully. I suppose I understand > the matter. > I have apparently the same problem as Alex has. But my connection is in > UTF-8 and I need ISO-8859-1. > The problem accrued as I've moved from my webspace to a vServer. > The old configuration shown by phpMyAdmin on MySQL 4.1.13 is: > character set client utf8 > (Globaler Wert) latin1 > character set connection utf8 > (Globaler Wert) latin1 > character set database latin1 > character set results utf8 > (Globaler Wert) latin1 > character set server latin1 > character set system utf8 > collation connection utf8_general_ci > (Globaler Wert) latin1_swedish_ci > collation database latin1_swedish_ci > collation server latin1_swedish_ci > The new configuration shown by phpMyAdmin on my new MySQL 5.0.32 is > exactly the same, the I set "SET NAMES latin1" via mysql-shell. > BUT: > Making "SHOW VARIABLES" at mysql-shell gives: > character_set_client latin1 > character_set_connection latin1 > character_set_database latin1 > character_set_filesystem binary > character set results latin1 > character set server latin1 > character set system utf8 > collation connection latin1_swedish_ci > collation database latin1_swedish_ci > collation server latin1_swedish_ci > asking for the values by PHP gives: > character_set_client utf8 > character_set_connection utf8 > character_set_database latin1 > character_set_filesystem binary > character_set_results utf8 > character_set_server latin1 > character_set_system utf8 > collation_connection utf8_general_ci > collation_database latin1_swedish_ci > collation_server latin1_swedish_ci > I need the character_set_client and character_set_connection in latin1. > The HTTP header sends to the browser ISO-8859-15. That should stay so, > because about 2.000 html pages are coded in this. I don't care for the > DB contect, then I have it local in some programm. My only wish is to > establish a working-encoding-connection between the PHP and DB. > Can You please tell what exactly I have to do? Please, understand I > can't reprogramm the application, I even don't want to, because it > worked before. I'm quit sure it's not correct setted up. You have the answer, but apparently lost it in your explanation. I'll quote: > The new configuration shown by phpMyAdmin on my new MySQL 5.0.32 is > exactly the same, the I set "SET NAMES latin1" via mysql-shell. You must tell to server, what encoding you want, every time you connecting to database. Just add execution of 'SET NAMES latin1 COLLATE whatever_collation_you_need' statement right after the moment you have connected to database in your script. P.S. I've read somewhere that it is possible to configure MySQL user to have specific encoding/collation without recompiling whole server/playing with variables every time user connecting to the server. But I've lost that manual or sumply misread it. All I can remember for now, it is something like CREATE USER 'user' WITH CHARACTER SET charset; Can anyone confirm it or tell more about it? -- Sincerely Yours, AnrDaemon <anrdaemon@freemail.ru> |
| |||
| Jerry Stuckle schrieb: > Marc wrote: >> alex schrieb: >>> >>> I made a simple script in PHP to dump data from tables which had non >>> standard characters. But the resulting page is viewed correctly in >>> iso-8859-1 encoding and not in UTF-8. >>> >>> At this moment i'm clueless were the problem lies. >> >> Hello, >> >> well, first of all, I'm newbie with MYSQL & Co., I have read all >> answers and followed the link reading them all carefully. I suppose I >> understand the matter. >> >> I have apparently the same problem as Alex has. But my connection is >> in UTF-8 and I need ISO-8859-1. >> >> The problem accrued as I've moved from my webspace to a vServer. >> >> The old configuration shown by phpMyAdmin on MySQL 4.1.13 is: >> >> character set client utf8 >> (Globaler Wert) latin1 >> character set connection utf8 >> (Globaler Wert) latin1 >> character set database latin1 >> character set results utf8 >> (Globaler Wert) latin1 >> character set server latin1 >> character set system utf8 >> collation connection utf8_general_ci >> (Globaler Wert) latin1_swedish_ci >> collation database latin1_swedish_ci >> collation server latin1_swedish_ci >> >> The new configuration shown by phpMyAdmin on my new MySQL 5.0.32 is >> exactly the same, the I set "SET NAMES latin1" via mysql-shell. >> >> BUT: >> >> Making "SHOW VARIABLES" at mysql-shell gives: >> >> character_set_client latin1 >> character_set_connection latin1 >> character_set_database latin1 >> character_set_filesystem binary >> character set results latin1 >> character set server latin1 >> character set system utf8 >> collation connection latin1_swedish_ci >> collation database latin1_swedish_ci >> collation server latin1_swedish_ci >> >> asking for the values by PHP gives: >> >> character_set_client utf8 >> character_set_connection utf8 >> character_set_database latin1 >> character_set_filesystem binary >> character_set_results utf8 >> character_set_server latin1 >> character_set_system utf8 >> collation_connection utf8_general_ci >> collation_database latin1_swedish_ci >> collation_server latin1_swedish_ci >> >> I need the character_set_client and character_set_connection in latin1. >> >> The HTTP header sends to the browser ISO-8859-15. That should stay so, >> because about 2.000 html pages are coded in this. I don't care for the >> DB contect, then I have it local in some programm. My only wish is to >> establish a working-encoding-connection between the PHP and DB. >> >> Can You please tell what exactly I have to do? Please, understand I >> can't reprogramm the application, I even don't want to, because it >> worked before. I'm quit sure it's not correct setted up. >> >> Thanks a lot in advance!!! >> >> Regards >> >> Marc >> > > Oops, I didn't notice you crossposted this to comp.databases.mysql. > > You indicated you had "non-standard" characters in the database. The > first question is - what charset is the data in the database in? And > exactly what are these "non-standard" characters? > Hello Jerry, sorry for crossposting. I think it's not only MYSQL problem, but also PHP problem. I have German umlauts in there. I guess the old DB used latin1 and the new one uses UTF-8 for internal corresponding. As I have found it, it acctually doesn't matter how the DB corresponds internal, then it's able to encode by request sent by client. And that's the point, I guess PHP doesn't say which encoding it would like to use. Or maybe it's enough to tell DB which encoding it should normally use talking to anything from outside. Right? So, I'm sorry for crossposting but I guess it's a mysql-php-problem. Thanks a lot for Your responce. Regards, Marc |
| |||
| Jerry Stuckle schrieb: > Marc wrote: >> Jerry Stuckle schrieb: >>> Marc wrote: >>>> alex schrieb: >>>>> >>>>> I made a simple script in PHP to dump data from tables which had >>>>> non standard characters. But the resulting page is viewed correctly >>>>> in iso-8859-1 encoding and not in UTF-8. >>>>> >>>>> At this moment i'm clueless were the problem lies. >>>> >>>> Hello, >>>> >>>> well, first of all, I'm newbie with MYSQL & Co., I have read all >>>> answers and followed the link reading them all carefully. I suppose >>>> I understand the matter. >>>> >>>> I have apparently the same problem as Alex has. But my connection is >>>> in UTF-8 and I need ISO-8859-1. >>>> >>>> The problem accrued as I've moved from my webspace to a vServer. >>>> >>>> The old configuration shown by phpMyAdmin on MySQL 4.1.13 is: >>>> >>>> character set client utf8 >>>> (Globaler Wert) latin1 >>>> character set connection utf8 >>>> (Globaler Wert) latin1 >>>> character set database latin1 >>>> character set results utf8 >>>> (Globaler Wert) latin1 >>>> character set server latin1 >>>> character set system utf8 >>>> collation connection utf8_general_ci >>>> (Globaler Wert) latin1_swedish_ci >>>> collation database latin1_swedish_ci >>>> collation server latin1_swedish_ci >>>> >>>> The new configuration shown by phpMyAdmin on my new MySQL 5.0.32 is >>>> exactly the same, the I set "SET NAMES latin1" via mysql-shell. >>>> >>>> BUT: >>>> >>>> Making "SHOW VARIABLES" at mysql-shell gives: >>>> >>>> character_set_client latin1 >>>> character_set_connection latin1 >>>> character_set_database latin1 >>>> character_set_filesystem binary >>>> character set results latin1 >>>> character set server latin1 >>>> character set system utf8 >>>> collation connection latin1_swedish_ci >>>> collation database latin1_swedish_ci >>>> collation server latin1_swedish_ci >>>> >>>> asking for the values by PHP gives: >>>> >>>> character_set_client utf8 >>>> character_set_connection utf8 >>>> character_set_database latin1 >>>> character_set_filesystem binary >>>> character_set_results utf8 >>>> character_set_server latin1 >>>> character_set_system utf8 >>>> collation_connection utf8_general_ci >>>> collation_database latin1_swedish_ci >>>> collation_server latin1_swedish_ci >>>> >>>> I need the character_set_client and character_set_connection in latin1. >>>> >>>> The HTTP header sends to the browser ISO-8859-15. That should stay >>>> so, because about 2.000 html pages are coded in this. I don't care >>>> for the DB contect, then I have it local in some programm. My only >>>> wish is to establish a working-encoding-connection between the PHP >>>> and DB. >>>> >>>> Can You please tell what exactly I have to do? Please, understand I >>>> can't reprogramm the application, I even don't want to, because it >>>> worked before. I'm quit sure it's not correct setted up. >>>> >>>> Thanks a lot in advance!!! >>>> >>>> Regards >>>> >>>> Marc >>>> >>> >>> Oops, I didn't notice you crossposted this to comp.databases.mysql. >>> >>> You indicated you had "non-standard" characters in the database. The >>> first question is - what charset is the data in the database in? And >>> exactly what are these "non-standard" characters? >>> >> >> Hello Jerry, >> >> sorry for crossposting. I think it's not only MYSQL problem, but also >> PHP problem. >> >> I have German umlauts in there. I guess the old DB used latin1 and the >> new one uses UTF-8 for internal corresponding. >> >> As I have found it, it acctually doesn't matter how the DB corresponds >> internal, then it's able to encode by request sent by client. And >> that's the point, I guess PHP doesn't say which encoding it would like >> to use. Or maybe it's enough to tell DB which encoding it should >> normally use talking to anything from outside. >> >> Right? >> >> So, I'm sorry for crossposting but I guess it's a mysql-php-problem. >> >> Thanks a lot for Your responce. >> >> >> Regards, >> >> Marc >> > > Marc, > > No, it's my fault for not noticing the cross-posting in the first place. > > You probably now have a mismatch between your connection and your table. > Besides the charset used by the table, you have a charset used by the > connection. I suspect you have a mismatch here. After connecting, call: > > mysql_query("SET NAMES 'latin1'"); > > This should also set your connection to latin1. > Jerry, that's what I guess the problem is. I've tried to call the command at the mysql-shell... and got error 1064 (42000). Should it be called via the php script perhaps? That's not that comfortable way for me... Regards, Marc |
| ||||
| AnrDaemon schrieb: > Greetings, Marc. > In reply to Your message dated Monday, June 9, 2008, 19:31:01, > >>> You have the answer, but apparently lost it in your explanation. I'll quote: >>> >>>> The new configuration shown by phpMyAdmin on my new MySQL 5.0.32 is >>>> exactly the same, the I set "SET NAMES latin1" via mysql-shell. >>> You must tell to server, what encoding you want, every time you connecting to >>> database. >>> Just add execution of 'SET NAMES latin1 COLLATE whatever_collation_you_need' >>> statement right after the moment you have connected to database in your script. > >> thanks a lot for this advice. But it's not possible to change the whole >> project for this. That's why I would like to set it generally up. On the >> other side, I don't need any other encoding. > > You lost the point. > It is not "changing the whole project", it is the action that project must do > once in only one script - one that establishing connection to database. > It is, literally, one line of code to add to whole your project, and it will > serve you to the end of times. > > AnrDaemon, that seems that easy, but it cannot be the cleanest way. I don't feel so comfortable about it. It has worked already. I just would like to set everything right up. I'm sending the data from some external DB by one php script and I'm trying to add this simple line to it... It's gonna take some time, I to new on this stuff. I'm gonna report. Thanks a lot. Regards, Marc |