You are here

MySQL Character Encoding

Error message

  • Deprecated function: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in drupal_strip_dangerous_protocols() (line 1458 of /home2/crephoto/public_html/techblog/includes/common.inc).
  • Deprecated function: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in drupal_strip_dangerous_protocols() (line 1458 of /home2/crephoto/public_html/techblog/includes/common.inc).
  • Deprecated function: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in drupal_strip_dangerous_protocols() (line 1458 of /home2/crephoto/public_html/techblog/includes/common.inc).

I encountered a funky problem on this very site where certain characters in my news feeds were getting garbled in the database. I suspected it was a Unicode/UTF-8/etc problem, and upon exploration I discovered this suggestion. First backup the table(s) with the offending data:

$ mysqldump -uusername -ppassword --add-drop-table --default-character-set=latin1 database table > backup.sql

Then restore the table(s) with the following command:

mysql -uusername -ppassword --default-character-set=utf8 database < backup.sql

This in itself didn't completely solve the problem. When I examined the backup.sql file, I discovered it contained the following line:

/*!40101 SET NAMES latin1 */;

I commented that out and restored the table again (using the mysql command above). Voila, ça marche!