public function cp_db($sourceTable, $newTable, $where = '',$isForce = false)
{
$stime = microtime(true);
if (!empty($where) && (stripos($where, 'where') === false||stripos($where, 'WHERE') === false)) {
return ['code' => 400, 'message' => 'where 条件非法,必须带上where关键词'];
}
if (pdo_tableexists($newTable)) {
if ($isForce){
pdo_run(" DROP TABLE IF EXISTS ".tablename($newTable).";");
if (pdo_tableexists($newTable)){
return ['code' => 400, 'message' => $newTable . ' 强制删除失败!'];
}
}else{
return ['code' => 400, 'message' => $newTable . '已存在'];
}
}
pdo_run('create table ' . tablename($newTable) . ' like ' . tablename($sourceTable) . ';');
if (!pdo_tableexists($newTable)) {
return ['code' => 400, 'message' => $newTable . '创建失败:'.pdo_tableexists($newTable)];
}
pdo_run('insert into ' . tablename($newTable) . ' select * from ' . tablename($sourceTable). $where);
$has = pdo_tableexists($newTable);
return ['status' => $newTable,'time'=>microtime(true)-$stime];
}