PHP and MySQL umlauts communication

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Mat Son
    New Member
    • Jul 2011
    • 7

    PHP and MySQL umlauts communication

    Dear Community,

    I have a concern which I think I never had before - when I add data to my MySQL Database from PHP, the umlauts (ä,ö,ü) get encrypted.
    This happens only when I do it via PHP.
    I see the encrypted form when I log on to phpMyAdmin and when I visit the website.
    When I edit the content via phpMyAdmin I can use the normal umlauts and they are both shown good (on the website and phpMyAdmin).

    I tried several things to solve the problem, from adding to my mysql-class a query with SET NAMES 'UTF8' to using decode_utf8() function while retrieving data in mysql class.
    I set charset in html and removed it - nothing changes.

    My guess is that PHP is changing the umlauts in some way and sending the "wrong" data to MySQL Server.. is that right?

    I don't want to store the data in a wrong format, and since I can store the data from within phpMyAdmin, it should be possible to send the data in the same charset via PHP right?

    How can I solve this?

    Best regards,

    Matthias
  • johny10151981
    Top Contributor
    • Jan 2010
    • 1059

    #2
    I am not sure what your problem can be.
    but after successful connection run this statement, it might solve your problem
    Code:
     mysql_query("SET NAMES 'utf8'",conn);
    Last edited by zmbd; Oct 25 '12, 04:13 AM. Reason: Please format posted code using the <CODE/> button.

    Comment

    • Mat Son
      New Member
      • Jul 2011
      • 7

      #3
      Yeah unfortunately I already tried that but still, when I enter data via PHP in my database the umlauts get encrypted..

      Comment

      • Mat Son
        New Member
        • Jul 2011
        • 7

        #4
        Okaay.. I got it by now.. I made a stupid mistake, my own files were not encoded as UTF-8.



        I wrote this little file to check where the error occurs.. and in the end, when I checked both html and mysql charsets, all was fine - except the content that was added via my php file.
        So I found out I have to encode the file as well, did that.. now everythings fine... thanks anyway ;-)

        Comment

        • johny10151981
          Top Contributor
          • Jan 2010
          • 1059

          #5
          Good then, but make sure your file is utf-8 format without BOM mark, otherwise it will be a problem for your browser

          Comment

          Working...