PHP备份数据库表
本文地址:http://www.tongxinmao.com/Article/Detail/id/411
public function backupAction()
{
$rs = ORM::for_table($this->tbl)->find_array();
$fileName=APP_ROOT.'/../xxx.sql';
$myfile = fopen($fileName, "w") or die("Unable to open file!");//打开存储文件
echo $myfile. " lines:".count($rs);
foreach($rs as $re)
{
$keyArr = array_keys($re);//获得对应的键值
$valueArr = array_values($re);//获得对应的值
$keyStr = '';
foreach ($keyArr as $key => $value) {
$keyStr .= "`".$value."`,";
}
$keyStr = substr($keyStr,0,strlen($keyStr)-1); //取出最后一个逗号
$valueStr = '';
// var_dump($valueArr);
foreach ($valueArr as $key => $value) {
$valueStr .= "'".$value."',";
}
//以上的处理只是对应sql的写法
$valueStr = substr($valueStr,0,strlen($valueStr)-1); //取出最后一个逗号
$sql = "insert into `{$this->tbl}`({$keyStr}) values({$valueStr})";
fwrite($myfile, $sql.";\r\n\r\n");
}
echo "备份表{$this->tbl}数据完成<br/>";
fclose($myfile);
}
上一篇:WCH BleAnalyzer USB描述符
下一篇:GetKeyState(), GetAsyncKeystate(), GetKeyboardSlate()