/** * replicate the table *@param$sourceTable string sourceTable, such as Mc_member *@param$newTable string newTable name, such as Mc_member_copy *@paramString $WHERE conditional on replication *@paramBool $isForce Indicates whether the command is enforced. If true, it is deleted before being copied *@return array
*/
public function cp_db($sourceTable.$newTable.$where = ' '.$isForce = false)
{
$stime = microtime(true);
// In order for you to use index copy, the WHERE condition must match exactly
if (!empty($where) && (stripos($where.'where') = = =false||stripos($where.'WHERE') = = =false)) {
return ['code'= >400.'message'= >'Where condition is illegal, must bring where keyword'];
}
if (pdo_tableexists($newTable)) {
if ($isForce) {// Delete it before copying it
pdo_run(" DROP TABLE IF EXISTS ".tablename($newTable).";");
if (pdo_tableexists($newTable)) {return ['code'= >400.'message'= >$newTable . 'Forcible deletion failed! ']; }}else{
return ['code'= >400.'message'= >$newTable . 'pre-existing']; }}// First copy the structure, then copy the data
pdo_run('create table ' . tablename($newTable).' like ' . tablename($sourceTable).'; ');
if(! pdo_tableexists($newTable)) {
return ['code'= >400.'message'= >$newTable . 'Failed to create :'.pdo_tableexists($newTable)];
}
// Start copying
pdo_run('insert into ' . tablename($newTable).' select * from ' . tablename($sourceTable). $where);
$has = pdo_tableexists($newTable);
return ['status'= >$newTable.'time'=>microtime(true) -$stime];
}
Copy the code