3 fixes character set and engine=InnoDB.. in Mysql
7 class Pman_Core_UpdateDatabase_MysqlEngineCharset {
13 function __construct()
16 $this->loadIniFiles(); //?? shared???
17 $this->updateEngine(); // update the engine first - get's around 1000 character limit on indexes..
19 $this->updateCharacterSet();
24 function loadIniFiles()
26 // will create the combined ini cache file for the running user.
28 $ff = HTML_FlexyFramework::get();
29 $ff->generateDataobjectsCache(true);
30 $this->dburl = parse_url($ff->database);
32 $dbini = 'ini_'. basename($this->dburl['path']);
35 $iniCache = $ff->DB_DataObject[$dbini];
37 $this->schema = parse_ini_file($iniCache, true);
38 $this->links = parse_ini_file(preg_replace('/\.ini$/', '.links.ini', $iniCache), true);
44 function updateCharacterSet()
46 foreach (array_keys($this->schema) as $tbl){
48 if(strpos($tbl, '__keys') !== false ){
52 $ce = DB_DataObject::factory('core_enum');
56 CCSA.character_set_name csname,
57 CCSA.collation_name collatename
59 information_schema.`TABLES` T,
60 information_schema.`COLLATION_CHARACTER_SET_APPLICABILITY` CCSA
62 CCSA.collation_name = T.table_collation
64 T.table_schema = '{$ce->database()}' -- COLLATE utf8_general_ci
66 T.table_name = '{$tbl}' -- COLLATE utf8_general_ci
71 if($ce->csname == 'utf8' && $ce->collatename == 'utf8_general_ci'){
72 echo "utf8: SKIP $tbl\n";
75 // this used to be utf8_unicode_ci
76 //as the default collation for stored procedure parameters is utf8_general_ci and you can't mix collations.
78 $ce = DB_DataObject::factory('core_enum');
79 // not sure why, but convert to does not actually change the 'charset=' bit..
80 $ce->query("ALTER TABLE $tbl CHARSET=utf8");
81 $ce->query("ALTER TABLE {$tbl} CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci");
82 echo "utf8: FIXED {$tbl}\n";
86 function updateEngine()
88 foreach (array_keys($this->schema) as $tbl){
90 if(strpos($tbl, '__keys') !== false ){
94 $ce = DB_DataObject::factory('core_enum');
96 $ce->query("select engine from information_schema.tables where table_schema='{$ce->database()}' and table_name = '{$tbl}'");
100 if($ce->engine == 'InnoDB' ){
101 echo "InnoDB: SKIP $tbl\n";
104 // this used to be utf8_unicode_ci
105 //as the default collation for stored procedure parameters is utf8_general_ci and you can't mix collations.
107 $ce = DB_DataObject::factory('core_enum');
108 $ce->query("ALTER TABLE $tbl ENGINE=InnoDB");
109 echo "InnoDB: FIXED {$tbl}\n";