Little code to convert db and all tables to utf8 or an other charset

Hi,

Hereby a little code to convert db and all tables to utf8 or an other charset, if someone need it

Nac


$database={db_name};

$alter_database_charset_sql = “ALTER DATABASE “.$database.” CHARACTER SET utf8 COLLATE utf8_unicode_ci”;
sc_exec_sql($alter_database_charset_sql,“conn_mysql”);

sc_lookup(rs, “SHOW TABLES”);
if ({rs} === false)
{
echo “Access error. Message=”. {rs_erro} ;
}
elseif (empty({rs}))
{
echo “Select command didn’t return data”;
}
else
{
$i=0;
while (isset({rs[$i][0]})){
$mtable = {rs[$i][0]};

	$alter_table_sql = "ALTER TABLE ".$mtable." CONVERT TO CHARACTER SET utf8  COLLATE utf8_unicode_ci";
	sc_exec_sql($alter_table_sql,"conn_mysql");
	
	echo "<pre>";
	var_dump($mtable);
	echo "</pre>";
	
	$i++;
}

}

Thanks for share :wink:

BTW, you can do this, on HeidiSQL, with “Massive Edit Table” (for MySQL and MariaDB)

[QUOTE=Giu;35369]Thanks for share :wink:

BTW, you can do this, on HeidiSQL, with “Massive Edit Table” (for MySQL and MariaDB)[/QUOTE]

Very nice! Copied it to the faq’s on scriptcase.eu