12.14
php
AD
Note
Inherited a db which was supposed to be utf8 but full of latin1...
define the following db connections:
var $default = array(
'driver' => 'mysql',
'persistent' => false,
'host' => 'localhost',
'login' => 'me',
'password' => 'password',
'database' => 'same',
'prefix' => '',
'encoding' => 'UTF8'
);
var $wrong = array(
'driver' => 'mysql',
'persistent' => false,
'host' => 'localhost',
'login' => 'me',
'password' => 'password',
'database' => 'same',
'prefix' => '',
'encoding' => 'latin1'
);
type "cake fix_charset".
There are other ways if the speed of the script is a problem: http://www.mysqlperformanceblog.com/2007/12/18/fixing-column-encoding-mess-in-mysql/ but
Inherited a db which was supposed to be utf8 but full of latin1...
define the following db connections:
var $default = array(
'driver' => 'mysql',
'persistent' => false,
'host' => 'localhost',
'login' => 'me',
'password' => 'password',
'database' => 'same',
'prefix' => '',
'encoding' => 'UTF8'
);
var $wrong = array(
'driver' => 'mysql',
'persistent' => false,
'host' => 'localhost',
'login' => 'me',
'password' => 'password',
'database' => 'same',
'prefix' => '',
'encoding' => 'latin1'
);
type "cake fix_charset".
There are other ways if the speed of the script is a problem: http://www.mysqlperformanceblog.com/2007/12/18/fixing-column-encoding-mess-in-mysql/ but
- <?php
- class FixCharsetShell extends Shell {
- function main() {
- $db =& ConnectionManager::getDataSource('default');
- $tables = $db->listSources();
- $Right = new Model(null, $tables[0], 'default');
- $Wrong = new Model(null, $tables[0] , 'wrong');
- foreach($tables as $table) {
- $this->hr();
- $this->out("Processing $table");
- $Wrong->setSource($table);
- $Right->setSource($table);
- $page = 1;
- $limit = 100;
- ((($page - 1) * $limit) + 1),
- ));
- foreach($data as $row) {
- $Right->create();
- $Right->save($row['Model']);
- }
- $page++;
- }
- }
- }
- }
Parsed in 0.044 seconds, using GeSHi 1.0.7.14