我在尝试通过PDO执行的SQL语句遇到麻烦。没有异常只会引发警告:“ sh:1:DELETE:not found”。我不确定错误是否出在我的语法中或pdo的安装/设置是否有帮助?
try {
$ConnectionObj = new PDO("mysql:host=localhost;dbname=Person", 'user', '1234');
$ConnectionObj->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$SqlStr = "DELETE FROM Details WHERE EmailAddress = '".$EmailAddrStr."' ";
exec($SqlStr);
//echo "Person deleted"."\n";
}
catch (PDOException $exception) {
echo $exception;
}
exec()
不是PDO函数,它用于运行外部应用程序:
exec
(PHP 4, PHP 5, PHP 7)
exec — Execute an external program
Description
exec ( string $command [, array &$output [, int &$return_var ]] ) : string
exec() executes the given command.
相反,请执行以下操作:
$conn = new PDO('mysql:host=localhost;dbname=db', 'usr', 'pass');
$sql = "DELETE FROM Details WHERE EmailAddress = :addr";
$stmt = $conn->prepare($sql);
$stmt->execute([':addr' => $EmailAddrStr]);
可以找到更多信息here: