问题描述
我有以下 PHP 代码,它从我的表中删除一行。我想在删除后添加以重新排列自动增量。这是临时表(最多 20 行),但用户希望看到计数正确。
我要添加的行如下:
ALTER TABLE tblmonitor AUTO_INCREMENT = 1
我的代码原样,没有上面的行:
if ($action == "deleteChanges") {
$monitor_id = $_REQUEST['monitor_id'];
$sql = 'DELETE FROM tblmonitor WHERE monitor_id = "' . $monitor_id . '"';
$sql = $connection->query($sql);
$error = $connection->errorInfo();
if ($error[1] == null) {
$result = array(
'success' => true,'message' => 'Record has been deleted successfully.'
);
echo json_encode($result);
} else {
$result = array(
'success' => false,'message' => $error[2]
);
echo json_encode($result);
}
}
我想在 DELETE sql
之后添加它,新代码将如下所示:
$sql = 'DELETE FROM tblmonitor WHERE monitor_id = "' . $monitor_id . '"';
$sql = 'ALTER TABLE tblmonitor AUTO_INCREMENT = 1';
$sql = $connection->query($sql);
$error = $connection->errorInfo();
这不是正确的方法,但我该如何修复它并使其在出现错误时正常工作?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)