无效的PDO查询不会返回错误

Tim*_*imm 10 mysql pdo

下面的第二个SQL语句在phpMyAdmin中返回错误:

SET @num=2000040;
INSERT INTO artikel( artikel_nr, lieferant_nr, bezeichnung_1, bezeichnung_1 )
SELECT @num := @num +1 AS anum, 70338, f2, f3
FROM import
WHERE id >1
Run Code Online (Sandbox Code Playgroud)

MySQL说:

#1110 - Column 'bezeichnung_1' specified twice
Run Code Online (Sandbox Code Playgroud)

全对了.但是,当我使用此函数在Symfony 1.4中运行查询时:

// run sql query
// http://erisds.co.uk/symfony/snippet-creating-debugging-complex-sql-queries-in-symfony
// http://stackoverflow.com/questions/5434702/php-quick-refactoring
// param $sql:    the query to run
// param $silent: bool if errors should be ignored
// throws:        pdo error info if statement failed and $silent=false
// returns:       pdo-statement (use for looping over result rows and error messages)
public static function runQuery($sql, $silent=false)
{
  $conn = Propel::getConnection();
  $pdo_statement = $conn->prepare($sql);

  $error = null;
  try
  {
    $pdo_statement->execute();
  }
  catch (Exception $e)
  {
    $error = $e->getMessage();
  }

  if ( !$error )
  {
    $pdo_error = $pdo_statement->errorInfo();
    $error = $pdo_error[2];
  }
  if ( !$silent && $error ) throw new Exception($error);

  return $pdo_statement;
}
Run Code Online (Sandbox Code Playgroud)

没有错误被抛出.这两个SQL语句必须同时提交,因为它们相互依赖.错误查询是根据用户输入构造的.我需要重新获得该错误,否则我无法判断数据库是否已更改,我无法告诉用户它.

你知道为什么PDO不抱怨无效声明,如果不能这样做,如何获得成功/失败信息?

BTW如果没有重复的列,查询会更新数据库.

这是PDOStatement类的链接:http://www.php.net/manual/en/class.pdostatement.php

Tim*_*imm 9

这是预期的行为.由于有两个语句且第一个语句有效,因此必须使用nextRowset()

try
  {
    $pdo_statement->execute();
    while ($pdo_statement->nextRowset()) {/* https://bugs.php.net/bug.php?id=61613 */};
  }
Run Code Online (Sandbox Code Playgroud)

资料来源:bugs.php.net/bug.php?id=61613