Posted By

ginoplusio on 02/11/10


Tagged

mysql utf8 set char encoding collation


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

ginoplusio


PHP function to change collation on MySQL db


 / Published in: PHP
 

URL: http://www.barattalo.it/2010/02/11/php-function-to-fix-collation-on-database-fields-of-mysql/

Function to fix char set and collation on mysql tables, see this link for examples and more infos.

  1. function fix_encoding($reg='//',$set='utf8',$collation='utf8_general_ci') {
  2. $res = mysql_query("SHOW TABLES");
  3. while ($row = mysql_fetch_row($res)) {
  4. if (preg_match($reg,$row[0])) {
  5. mysql_query("ALTER TABLE " . $row[0] . " CONVERT TO CHARACTER SET $set COLLATE $collation");
  6. echo $row[0] . " converted<br />";
  7. }
  8.  
  9. }
  10. }

Report this snippet  

You need to login to post a comment.