From: toyomoyo Date: Wed, 18 Oct 2006 07:26:04 +0000 (+0000) Subject: merged added code to force mysql db to change default encoding during fresh installation X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=a6eb09d977be90eacfb066005bc373f0b31b7878;p=moodle.git merged added code to force mysql db to change default encoding during fresh installation --- diff --git a/admin/index.php b/admin/index.php index cc6dcb137e..de37e4aab1 100644 --- a/admin/index.php +++ b/admin/index.php @@ -140,6 +140,8 @@ /// Both old .sql files and new install.xml are supported /// But we prioritise install.xml (XMLDB) if present + + change_db_encoding(); // first try to change db encoding to utf8 $status = false; if (file_exists("$CFG->libdir/db/install.xml")) { $status = install_from_xmldb_file("$CFG->libdir/db/install.xml"); //New method diff --git a/lib/ddllib.php b/lib/ddllib.php index 4c48f7e1a1..2eefddabc3 100644 --- a/lib/ddllib.php +++ b/lib/ddllib.php @@ -1140,4 +1140,15 @@ function rename_index($table, $index, $newname, $continue=true, $feedback=true) return execute_sql_arr($sqlarr, $continue, $feedback); } +/* trys to change default db encoding to utf8, if empty db + */ +function change_db_encoding() { + global $CFG, $db; + // try forcing utf8 collation, if mysql db and no tables present + if (!$db->Metatables() && ($CFG->dbtype=='mysql')) { + $SQL = 'ALTER DATABASE '.$CFG->dbname.' CHARACTER SET utf8'; + execute_sql($SQL, false); // silent, if it fails it fails + } +} + ?>