>phpMyAdmin可以成功恢复带有LONGBLOG数据的1.6MB转储文件。我正在尝试复制此功能,但我的功能似乎不起作用。我收到分段错误错误,它似乎从未执行任何备份文件的代码。(但它确实会删除表)
我相信段错误是在做preg_split时。
以下是恢复的例程:(这适用于没有 LONGBLOB 数据的小文件)
function do_restore()
{
$password=$this->input->post('password');
if(!$this->Employee->authentication_check($password))
{
echo json_encode(array('success'=>false,'message'=>"failure"));
exit();
}
else
{
$sq=file_get_contents($_FILES["file"]["tmp_name"]);
$this->db->trans_start();
$this->db->query('SET foreign_key_checks = 0');
$tables = $this->db->list_tables();
foreach ($tables as $table)
{
$this->db->query('drop table '.$table);
}
$this->db->query('SET foreign_key_checks = 1');
$queries = preg_split("/;+(?=([^'|^\']*['|\'][^'|^\']*['|\'])*[^'|^\']*[^'|^\']$)/", $sq);
foreach ($queries as $query)
{
if($query)
{
$this->db->query($query);
}
}
$this->db->trans_complete();
echo json_encode(array('success'=>true,'message'=>"success"));
}
}
看起来您需要添加一些代码以确保您拥有有效的文件内容。在调用 preg_split
之前,您没有检查以确保$sq
有效(不为空或 null)。