O
O
Optimus2015-12-07 17:08:15
PHP
Optimus, 2015-12-07 17:08:15

How to get detailed information about a PDO error?

Uncaught exception 'PDOException' with message 'SQLSTATE[HY093]:
Invalid parameter number: parameter was not defined' in (line 118) Stack trace: #0
PDOStatement->execute() #1 {main} thrown in
Line 118 is $b->execute();in General it is clear that he says that the wrong number of parameters and some is not defined, but somehow you can make him show which one?
Tried to put:

echo $pdo->errorCode();
print_r($pdo->errorInfo());

But he doesn't show me anything at all.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2015-12-07
Pyan @marrk2

Catch the PDOException, it contains more detailed info by mistake. Plus, in the catch block, you can process the PDOStatement request object, from which you can extract data using the debugDumpParams() method. For example:

try {
  $stmt->execute($sq);
} catch (PDOException $e) {
  print_r($e->getMessage());
  $stmt->debugDumpParams();
}

php.net/manual/ru/class.pdostatement.php
php.net/manual/ru/class.pdoexception.php

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question