[英]How clone all data from one database to another one in Codeigniter
I am going to move all data from the live stage database into another new database.我要将所有数据从实时阶段数据库移动到另一个新数据库中。 The project is based on Codeignitor.
该项目基于 Codeignitor。 For now I am using dump file but it's really slow to handle them.
现在我正在使用转储文件,但处理它们真的很慢。
$temp_path = './db/dump/old_backup.sql';
// Create temporary table
echo "Preparing temporary database ..... \n";
$this->createTemporarDB();
// Make Dump from live db
echo "Preparing backup from live database ..... \n";
$backup = $this->exportDumpFromDB('default', 'old_backup.sql');
write_file($temp_path, $backup, 'w+');
$this->new_db = $this->load->database('new_db', true);
$temp_line = '';
$lines = file('./db/dump/old_backup.sql');
foreach ($lines as $line) {
if (substr($line, 0, 2) == '--' || $line == '' || substr($line, 0, 1) == '#') {
continue;
}
$temp_line .= $line;
// Display percentage of temp data
if (substr(trim($line), -1, 1) == ';') {
$this->temp_db->query($temp_line);
$temp_line = '';
}
$index++;
}
Is there any best method to solve my issues( latency issue, I need to speed up ).有没有最好的方法来解决我的问题(延迟问题,我需要加快速度)。 Thank you.
谢谢你。
I fixed this issue.我修复了这个问题。 Attached my approach here.
在这里附上我的方法。
$tables = $this->db->query("SHOW TABLES FROM [old db name]")->result_array();
$this->temp_db = $this->load->database[new db name]', true);
foreach ($tables as $key => $val) {
$this->temp_db->query('CREATE TABLE ' . $val['Tables_in_squirrel'] . ' LIKE [old db name].' . $val['Tables_in_squirrel']);
$this->temp_db->query('INSERT ' . $val['Tables_in_[old db name]'] . ' SELECT * FROM squirrel.' . $val['Tables_in_squirrel']);
}
}
This is the code based on Codeigniter.这是基于 Codeigniter 的代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.