PDO SQL删除语句未找到。

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

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?

  1. try {
  2. $ConnectionObj = new PDO("mysql:host=localhost;dbname=Person", 'user', '1234');
  3. $ConnectionObj->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  4. $SqlStr = "DELETE FROM Details WHERE EmailAddress = '".$EmailAddrStr."' ";
  5. exec($SqlStr);
  6. //echo "Person deleted"."\n";
  7. }
  8. catch (PDOException $exception) {
  9. echo $exception;
  10. }

答案1

得分: 4

exec()不是PDO函数,它用于运行外部应用程序:

  1. exec
  2. (PHP 4, PHP 5, PHP 7)
  3. exec 执行外部程序
  4. 描述
  5. exec ( string $command [, array &$output [, int &$return_var ]] ) : string
  6. exec() 执行给定的命令。
  7. 相反,可以这样做:
  8. ```php
  9. $conn = new PDO('mysql:host=localhost;dbname=db', 'usr', 'pass');
  10. $sql = "DELETE FROM Details WHERE EmailAddress = :addr";
  11. $stmt = $conn->prepare($sql);
  12. $stmt->execute([':addr' => $EmailAddrStr]);

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

英文:

exec() isn't a PDO function, it's used to run external applications:

  1. exec
  2. (PHP 4, PHP 5, PHP 7)
  3. exec Execute an external program
  4. Description
  5. exec ( string $command [, array &$output [, int &$return_var ]] ) : string
  6. exec() executes the given command.

Instead, do something like this:

  1. $conn = new PDO('mysql:host=localhost;dbname=db', 'usr', 'pass');
  2. $sql = "DELETE FROM Details WHERE EmailAddress = :addr";
  3. $stmt = $conn->prepare($sql);
  4. $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:

确定