3 fixes character set and engine=InnoDB.. in Mysql
7 class Pman_Core_UpdateDatabase_MysqlEngineCharset {
13 function __construct()
16 $this->loadIniFiles(); //?? shared???
17 $this->updateCharacterSet();
18 $this->updateEngine();
23 function loadIniFiles()
25 // will create the combined ini cache file for the running user.
27 $ff = HTML_FlexyFramework::get();
28 $ff->generateDataobjectsCache(true);
29 $this->dburl = parse_url($ff->database);
31 $dbini = 'ini_'. basename($this->dburl['path']);
34 $iniCache = $ff->DB_DataObject[$dbini];
36 $this->schema = parse_ini_file($iniCache, true);
37 $this->links = parse_ini_file(preg_replace('/\.ini$/', '.links.ini', $iniCache), true);
43 function updateCharacterSet()
45 foreach (array_keys($this->schema) as $tbl){
47 if(strpos($tbl, '__keys') !== false ){
51 $ce = DB_DataObject::factory('core_enum');
55 CCSA.character_set_name csname,
56 CCSA.collation_name collatename
58 information_schema.`TABLES` T,
59 information_schema.`COLLATION_CHARACTER_SET_APPLICABILITY` CCSA
61 CCSA.collation_name = T.table_collation
63 T.table_schema = '{$ce->database()}' -- COLLATE utf8_general_ci
65 T.table_name = '{$tbl}' -- COLLATE utf8_general_ci
70 if($ce->csname == 'utf8' && $ce->collatename == 'utf8_general_ci'){
71 echo "utf8: SKIP $tbl\n";
74 // this used to be utf8_unicode_ci
75 //as the default collation for stored procedure parameters is utf8_general_ci and you can't mix collations.
77 $ce = DB_DataObject::factory('core_enum');
78 // not sure why, but convert to does not actually change the 'charset=' bit..
79 $ce->query("ALTER TABLE $tbl CHARSET=utf8");
80 $ce->query("ALTER TABLE {$tbl} CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci");
81 echo "utf8: FIXED {$tbl}\n";
85 function updateEngine()
87 foreach (array_keys($this->schema) as $tbl){
89 if(strpos($tbl, '__keys') !== false ){
93 $ce = DB_DataObject::factory('core_enum');
95 $ce->query("select engine from information_schema.tables where table_schema='{$ce->database()}' and table_name = '{$tbl}'");
99 if($ce->engine == 'InnoDB' ){
100 echo "InnoDB: SKIP $tbl\n";
103 // this used to be utf8_unicode_ci
104 //as the default collation for stored procedure parameters is utf8_general_ci and you can't mix collations.
106 $ce = DB_DataObject::factory('core_enum');
107 $ce->query("ALTER TABLE $tbl ENGINE=InnoDB");
108 echo "InnoDB: FIXED {$tbl}\n";