PHP function to change collation on MySQL db


/ Published in: PHP
Save to your folder(s)

Function to fix char set and collation on mysql tables, see [this link](http://www.barattalo.it/2010/02/11/php-function-to-fix-collation-on-database-fields-of-mysql/ "Fix encoding on db")
for examples and more infos.


Copy this code and paste it in your HTML
  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. }

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.