Return to Snippet

Revision: 23673
at February 11, 2010 04:53 by ginoplusio


Initial Code
function fix_encoding($reg='//',$set='utf8',$collation='utf8_general_ci') {
	$res = mysql_query("SHOW TABLES");
	while ($row = mysql_fetch_row($res)) {
		if (preg_match($reg,$row[0])) {
			mysql_query("ALTER TABLE " . $row[0] . " CONVERT TO CHARACTER SET $set COLLATE $collation");
			echo $row[0] . " converted<br />";
		}
		
	}
}

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

Initial Description
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.

Initial Title
PHP function to change collation on MySQL db

Initial Tags
mysql

Initial Language
PHP