有一个大表,我需要将它的内容移动到一个具有不同结构的表.这些表位于不同的数据库中.为此,我使用的是PHP脚本.但是脚本不能按照我想要的方式工作.它过度复制,永不停止.也许这是一个愚蠢而简单的问题,但是现在我的脑袋在旋转,从尝试但我不能指责问题.这项工作需要立即完成.如果你帮忙我会很高兴的.这里的代码片段:
function copy_table()
{
$this->load->database();
$num_rows = $this->db->get('orj_table')->num_rows();
$offset = 0;
$limit = 500;
while ($offset <= $num_rows)
{
$this->load->database();
//Query for original table
//......
$this->db->limit($limit, $offset);
$records = $this->db->get('orj_table')->result_array();
$this->db->close();
//Open a connection to new database.
$this->db_new = $this->load->database('new', TRUE);
foreach($records as $record)
{
$data1 = $record['data1'];
$data2 = $record['data2'];
$datas[] = array('data1 => $record['data1'],
'data2 => $record['data2']
);
}
//Insert 500 records at one time with "insert_batch"
$sorgu = $this->db_yeni->insert_batch('new_table', datas);
$this->db->close();
$offset += 500;
}
}
Run Code Online (Sandbox Code Playgroud)