我想试试半天......
我有一个脚本,根据数据库进行计算,看是否应该删除任何行。
$number = count($INSERT)-count($INDB);
$ number变量将是
1.和2.工作 - 但是3.给我一个错误。
if($number < 0){
$limit = abs($number);
echo "DELETE FROM pversions
WHERE fk_p_id = $pid
ORDER BY pversion_id DESC
LIMIT $limit";
$remVersions = $pdo->prepare("
DELETE FROM pversions
WHERE fk_p_id = :pid
ORDER BY pversion_id DESC
LIMIT :lmt");
$remVersions->execute(array(":pid" => $pid, ":lmt" => $limit));
$left = count($versions)-$limit;
}
回声可能会返回:
DELETE FROM pversions WHERE fk_p_id = 1 ORDER BY pversion_id DESC LIMIT 1
但是这给了我这个PDO例外:
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]:
Syntax error or access violation: 1064 You have an error in your SQL syntax;
check the manual that corresponds to your MariaDB server version for the right syntax
to use near ''1'' at line 4'
如果我从上面获取回声的确切输出并在PhpMyAdmin中输入,则完全没有问题。它完全像我想要的那样执行任务。
如果我删除LIMIT :lmt
错误未显示,则会删除所有行。
所以我很确定错误是在“LIMIT”中。
希望有人能告诉我这里我做错了什么。