Mysql database in UTF8, PHP shows latin1 (iso-8859-1)

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • alex

    Mysql database in UTF8, PHP shows latin1 (iso-8859-1)

    I've converted a latin1 database I have to utf8. The process has been:

    # mysqldump -u root -p --default-character-set=latin1 -c --insert-ignore
    --skip-set-charset mydb mydb.sql

    # iconv -f ISO-8859-1 -t UTF-8 mydb.sql mydb_utf8.sql

    [then i replaced all CHARSET=latin1 to CHARSET=utf8 in the file, and
    checked in the editor that non default characters as accents were viewed
    correctly using UTF8 charset]

    mysqlCREATE DATABASE mydb_utf8 CHARACTER SET utf8 COLLATE utf8_general_ci ;

    # mysql -u root -p --default-character-set=utf8 mydb_utf8 < mydb_utf8.sql


    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.


    ..alex
  • Norbert Tretkowski

    #2
    Re: Mysql database in UTF8, PHP shows latin1 (iso-8859-1)

    Am Fri, 04 Apr 2008 10:11:16 +0200 schrieb alex:
    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.


    I guess using "set names utf8" should help.

    Norbert

    Comment

    • alex

      #3
      Re: Mysql database in UTF8, PHP shows latin1 (iso-8859-1)

      En/na Norbert Tretkowski ha escrit:
      Am Fri, 04 Apr 2008 10:11:16 +0200 schrieb alex:
      >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.
      >

      >
      I guess using "set names utf8" should help.
      >
      Yes, it helps, but why should i change my app?

      I mean, if the database is set to utf8, the tables are utf8 too (and
      just to check, i've also set under [client], [mysqld] and [server] the
      value default_charact er_set=utf8), shouldn't php return me the string as
      utf8?

      Isn't this a bit bugged?

      Comment

      • Michael Fesser

        #4
        Re: Mysql database in UTF8, PHP shows latin1 (iso-8859-1)

        ..oO(alex)
        >En/na Norbert Tretkowski ha escrit:
        >Am Fri, 04 Apr 2008 10:11:16 +0200 schrieb alex:
        >>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.
        >>
        >http://dev.mysql.com/doc/refman/5.0/...onnection.html
        >>
        >I guess using "set names utf8" should help.
        >>
        >
        >Yes, it helps, but why should i change my app?
        >
        >I mean, if the database is set to utf8, the tables are utf8 too (and
        >just to check, i've also set under [client], [mysqld] and [server] the
        >value default_charact er_set=utf8), shouldn't php return me the string as
        >utf8?
        >
        >Isn't this a bit bugged?
        Just storing the data as UTF-8 is not enough. You also have to set the
        connection between MySQL and your script to UTF-8 and PHP has to send a
        correct HTTP header back to the browser.

        Micha

        Comment

        • alex

          #5
          Re: Mysql database in UTF8, PHP shows latin1 (iso-8859-1)

          En/na Michael Fesser ha escrit:
          >
          Just storing the data as UTF-8 is not enough. You also have to set the
          connection between MySQL and your script to UTF-8 and PHP has to send a
          correct HTTP header back to the browser.
          Ok, i know that i must send correct headers, but still having this
          variables:

          +--------------------------+----------------------------+
          | Variable_name | Value |
          +--------------------------+----------------------------+
          | character_set_c lient | utf8 |
          | character_set_c onnection | utf8 |
          | character_set_d atabase | utf8 |
          | character_set_f ilesystem | binary |
          | character_set_r esults | utf8 |
          | character_set_s erver | utf8 |
          | character_set_s ystem | utf8 |
          | character_sets_ dir | /usr/share/mysql/charsets/ |
          +--------------------------+----------------------------+

          The output is ISO, and that is what freaks me out. :P

          Comment

          • Jerry Stuckle

            #6
            Re: Mysql database in UTF8, PHP shows latin1 (iso-8859-1)

            alex wrote:
            En/na Michael Fesser ha escrit:
            >
            >>
            >Just storing the data as UTF-8 is not enough. You also have to set the
            >connection between MySQL and your script to UTF-8 and PHP has to send a
            >correct HTTP header back to the browser.
            >
            Ok, i know that i must send correct headers, but still having this
            variables:
            >
            +--------------------------+----------------------------+
            | Variable_name | Value |
            +--------------------------+----------------------------+
            | character_set_c lient | utf8 |
            | character_set_c onnection | utf8 |
            | character_set_d atabase | utf8 |
            | character_set_f ilesystem | binary |
            | character_set_r esults | utf8 |
            | character_set_s erver | utf8 |
            | character_set_s ystem | utf8 |
            | character_sets_ dir | /usr/share/mysql/charsets/ |
            +--------------------------+----------------------------+
            >
            The output is ISO, and that is what freaks me out. :P
            >
            Check Micha's comment again:

            "...and PHP has to send a correct HTTP header back to the browser."

            The dataset connection and charset have nothing to do with the charset
            sent in the page header. You can set the correct charset for the page
            in your Apache server or in PHP.

            --
            =============== ===
            Remove the "x" from my email address
            Jerry Stuckle
            JDS Computer Training Corp.
            jstucklex@attgl obal.net
            =============== ===

            Comment

            • Willem Bogaerts

              #7
              Re: Mysql database in UTF8, PHP shows latin1 (iso-8859-1)

              it seems a php problem as when i execute "show variables" in an mysql
              console i get:
              >
              character_set_c lient=utf8
              >
              but from php i get:
              >
              character_set_c lient=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.

              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.

              Best regards,
              --
              Willem Bogaerts

              Application smith
              Kratz B.V.

              Comment

              • Michael Fesser

                #8
                Re: Mysql database in UTF8, PHP shows latin1 (iso-8859-1)

                ..oO(Willem Bogaerts)
                >it seems a php problem as when i execute "show variables" in an mysql
                >console i get:
                >>
                >character_set_ client=utf8
                >>
                >but from php i get:
                >>
                >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?
                >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

                Comment

                • Marc

                  #9
                  Mysql database in UTF8, PHP shoud show latin1, but it doesn't

                  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_c lient latin1
                  character_set_c onnection latin1
                  character_set_d atabase latin1
                  character_set_f ilesystem 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_c lient utf8
                  character_set_c onnection utf8
                  character_set_d atabase latin1
                  character_set_f ilesystem binary
                  character_set_r esults utf8
                  character_set_s erver latin1
                  character_set_s ystem utf8
                  collation_conne ction utf8_general_ci
                  collation_datab ase latin1_swedish_ ci
                  collation_serve r latin1_swedish_ ci

                  I need the character_set_c lient and character_set_c onnection 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

                  Comment

                  • Marc

                    #10
                    Re: Mysql database in UTF8, PHP shoud show latin1, but it doesn't

                    I'm sorry, I should mention, I use:

                    Debian Etch stable
                    Apache2
                    PHP 5

                    Comment

                    • Jerry Stuckle

                      #11
                      Re: Mysql database in UTF8, PHP shoud show latin1, but it doesn't

                      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_c lient latin1
                      character_set_c onnection latin1
                      character_set_d atabase latin1
                      character_set_f ilesystem 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_c lient utf8
                      character_set_c onnection utf8
                      character_set_d atabase latin1
                      character_set_f ilesystem binary
                      character_set_r esults utf8
                      character_set_s erver latin1
                      character_set_s ystem utf8
                      collation_conne ction utf8_general_ci
                      collation_datab ase latin1_swedish_ ci
                      collation_serve r latin1_swedish_ ci
                      >
                      I need the character_set_c lient and character_set_c onnection 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@attgl obal.net
                      =============== ===

                      Comment

                      • Jerry Stuckle

                        #12
                        Re: Mysql database in UTF8, PHP shoud show latin1, but it doesn't

                        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_c lient latin1
                        character_set_c onnection latin1
                        character_set_d atabase latin1
                        character_set_f ilesystem 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_c lient utf8
                        character_set_c onnection utf8
                        character_set_d atabase latin1
                        character_set_f ilesystem binary
                        character_set_r esults utf8
                        character_set_s erver latin1
                        character_set_s ystem utf8
                        collation_conne ction utf8_general_ci
                        collation_datab ase latin1_swedish_ ci
                        collation_serve r latin1_swedish_ ci
                        >
                        I need the character_set_c lient and character_set_c onnection 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@attgl obal.net
                        =============== ===

                        Comment

                        • AnrDaemon

                          #13
                          Re: Mysql database in UTF8, PHP shoud show latin1, but it doesn't

                          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_c lient latin1
                          character_set_c onnection latin1
                          character_set_d atabase latin1
                          character_set_f ilesystem 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_c lient utf8
                          character_set_c onnection utf8
                          character_set_d atabase latin1
                          character_set_f ilesystem binary
                          character_set_r esults utf8
                          character_set_s erver latin1
                          character_set_s ystem utf8
                          collation_conne ction utf8_general_ci
                          collation_datab ase latin1_swedish_ ci
                          collation_serve r latin1_swedish_ ci
                          I need the character_set_c lient and character_set_c onnection 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_collat ion_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@free mail.ru>

                          Comment

                          • Marc

                            #14
                            Re: Mysql database in UTF8, PHP shoud show latin1, but it doesn't

                            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_conn ection utf8_general_ci
                            >collation_data base latin1_swedish_ ci
                            >collation_serv er latin1_swedish_ ci
                            >>
                            >I need the character_set_c lient and character_set_c onnection 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

                            Comment

                            • Marc

                              #15
                              Re: Mysql database in UTF8, PHP shoud show latin1, but it doesn't

                              Hello AnrDaemon,

                              AnrDaemon schrieb:
                              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_conn ection utf8_general_ci
                              >collation_data base latin1_swedish_ ci
                              >collation_serv er latin1_swedish_ ci
                              >
                              >I need the character_set_c lient and character_set_c onnection 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_collat ion_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.
                              >
                              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?
                              >
                              >
                              I have read somewhere it should be necessary to recompile the whole
                              server... well, I have no idea about it yet.

                              I'm gonna look around for any advice for configuring MySQL user to have
                              specific encoding.

                              But still, isn't it possible to make general settings for this??

                              Thanks a lot for Your hints.

                              Regards,

                              Marc

                              Comment

                              Working...