简体   繁体   English

如何在 Codeigniter 中将所有数据从一个数据库克隆到另一个数据库

[英]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.

相关问题 如何在Codeigniter中将数据从一个视图回显到另一个视图? - How to echo data from one view to another one in Codeigniter? 如何通过使用会话将数据从一个功能传递到Codeigniter中的另一个功能? - How to pass data from one function to another in codeigniter by using session? 如何将数据从一个视图页面传递到codeigniter中的另一个视图? - how to pass the data from one view page to another view in codeigniter? Symfony-通过ID将所有值从一个对象克隆到另一个对象? - Symfony - clone all values from one object onto another by ID? 如何在codeigniter中从数据库中获取所有数据 - How to get all data from database in codeigniter 在mysql和Codeigniter中将值从一个数据库移动到另一个数据库 - Move values from one database to another in mysql and Codeigniter 在codeigniter中将数据库内容从一个表复制到另一个表 - Copy database contents from one table to another table in codeigniter 将数据从一个MYSQL数据库迁移到另一个数据库 - migrate data from one MYSQL database to another 在mysql中将数据从一个数据库插入另一个数据库 - Insert data from one database to another in mysql PHP SQL:如何将数据从一个html表单保存到多个数据库,或者如何自动将数据从一个数据库复制到另一个数据库 - PHP SQL : How to save data to multiple database from one html form OR how to copy data from one database to another database automatically
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM