$sql = "dSELECT * FROM users";
$dbQuery = $this->dbal->query($sql);
$dbError = $this->dbal->errorInfo();
$dbError 获取语法错误信息。
如果相同的用于准备好的语句,它在准备后不会返回任何错误。
此代码来自 php.net
<?php
/* Provoke an error -- bogus SQL syntax */
$stmt = $dbh->prepare('bogus sql');
if (!$stmt) {
echo "\nPDO::errorInfo():\n";
print_r($dbh->errorInfo());
}
ErrorInfo 不能以这种方式工作。我用
$dbQuery = $this->dbal->prequery($sql);
$dbError = $dbQuery->errorInfo(); // $this->dbal->errorInfo(); doesn't work, too.