PDO SQL删除语句未找到。

huangapple go评论77阅读模式
英文:

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:

huangapple
  • 本文由 发表于 2020年1月6日 17:55:49
  • 转载请务必保留本文链接:https://go.coder-hub.com/59609948.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定