英文:
PDO SQL Delete statement not found
问题
I'm having trouble with an SQL statement I'm trying to execute through PDO. No exceptions are thrown, only a warning: "sh: 1: DELETE: not found." I'm not sure if the error lies in my syntax or the installation/setup of PDO. Any help?
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;
}
英文:
I'm having trouble with an SQL statement I'm trying to execute through PDO. No exceptions are throw only a warning :"sh: 1: DELETE: not found". I'm not sure if the error lies in my syntax or the installation/setup of pdo any help?
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;
}
答案1
得分: 4
exec()
不是PDO函数,它用于运行外部应用程序:
exec
(PHP 4, PHP 5, PHP 7)
exec — 执行外部程序
描述
exec ( string $command [, array &$output [, int &$return_var ]] ) : string
exec() 执行给定的命令。
相反,可以这样做:
```php
$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]);
更多信息可以在这里找到:
英文:
exec()
isn't a PDO function, it's used to run external applications:
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.
Instead, do something like this:
$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]);
more info can be found here:
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论