0
$sql = "dSELECT * FROM users";
$dbQuery = $this->dbal->query($sql);
$dbError = $this->dbal->errorInfo();

$dbError gets the syntax error information.

If the same is used for prepared statement it doesn't return any error after prepare.

This code is from 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 doesn't work in this way. I use

$dbQuery = $this->dbal->prequery($sql);
$dbError = $dbQuery->errorInfo(); // $this->dbal->errorInfo(); doesn't work, too.
Alex Emilov
  • 1,243
  • 4
  • 19
  • 25
  • 1
    did you try [this answer](http://stackoverflow.com/questions/6263443/pdo-connection-test/6263868#6263868)? – Sascha Galley Jun 27 '11 at 17:43
  • Tried that, but non of this worked.Actually the silent mode is by default and it works with the dbal->query. – Alex Emilov Jun 27 '11 at 17:58
  • When I use: $this->dbal->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); var_dump(\PDO::ATTR_ERRMODE); everytime returns 3.SILENT, Warning or Exception it returns 3. – Alex Emilov Jun 27 '11 at 18:06

1 Answers1

0

The manual says:

If the database server successfully prepares the statement, PDO::prepare() returns a PDOStatement object. If the database server cannot successfully prepare the statement, PDO::prepare() returns FALSE or emits PDOException (depending on error handling).

That means that you don't have an object when it fails: you have a boolean FALSE.

Try changing the PDO error handling to PDO::ERRMODE_EXCEPTION.

Álvaro González
  • 142,137
  • 41
  • 261
  • 360