找不到 PDO SQL 删除语句



我在尝试通过PDO执行SQL语句时遇到问题。没有异常只抛出警告:"sh:1:删除:未找到"。我不确定错误是否出在我的语法或 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]);

更多信息可以在这里找到:

相关内容

  • 没有找到相关文章

最新更新