0

I am executing the following statement.

$mystring = <<<EOT
UPDATE sites_niche SET `short_review` = REPLACE(`short_review`, '’',"'");
EOT;

However, it doesnt work, as it would work if I placed it in my phpmyadmin. The culprit is this bad character ’ that character is simply not being replaced.

I tried to print the update statement to the screen and I get this:

UPDATE sites_niche SET `short_review` = REPLACE(`short_review`, '’',"'");

I think that the string gets garbled as soon as it goes to the database. My question is how do encode those sets of characters ’ so that they dont get garbled as soon as they go to the database.

Tobias Snoad
  • 320
  • 3
  • 9
Dmitry Makovetskiyd
  • 6,942
  • 32
  • 100
  • 160
  • 2
    Please have a read of http://www.joelonsoftware.com/articles/Unicode.html and https://dev.mysql.com/doc/refman/5.0/en/charset.html – VolkerK Sep 12 '12 at 07:35

2 Answers2

1

There are two problems that I am able to see in your posting .

If you dont know which is your encoding format you can use php mb_detect() function to check the character encoding format and use the identified format for the solutions below

  1. Update to mysql from php

Solution : - Your php code which is responsible for connecting to Mysql should use

mysql_set_charset ( string $charset [, resource $link_identifier = NULL ] ) 

2 .when you print characters are garbled

Solution : - You have to set the character encoding in the page doctype declaration otherwise you will see this garbled characters

Aravind.HU
  • 9,194
  • 5
  • 38
  • 50
  • i cant guess the encoding it doesnt work..see this: http://stackoverflow.com/questions/910793/detect-encoding-and-make-everything-utf-8 – Dmitry Makovetskiyd Sep 12 '12 at 08:17
  • hmm I had a faced a similar problem , while saving google translated content in to db , fixing the mysql charset solved this issue . As you said I got to know that google serves in UTF-8 , Looks like I have to hack phpmyadmin and get back to you and explain how your query works in phpmyadmin , WRB soon – Aravind.HU Sep 12 '12 at 08:41
  • What is the column Collation that you are using in the mysql in the table on which you are running this query – Aravind.HU Sep 12 '12 at 09:05
-1

You can use the iconv extension http://es.php.net/manual/en/function.iconv.php or mbstring http://es.php.net/manual/en/function.mb-convert-encoding.php to convert a string from one charset to other charset

Maks3w
  • 6,014
  • 6
  • 37
  • 42