ID: 43443
Updated by: [EMAIL PROTECTED]
Reported By: r dot wilczek at web-appz dot de
Status: Open
Bug Type: PDO related
Operating System: openSuse 10.3
PHP Version: 5.2.5
-Assigned To:
+Assigned To: johannes
New Comment:
IMHO this is not a bug. This is how PDO is designed.
PDO calls the constructor of the PDO_Statement class. The constructor
of a class cannot return false. Its only way to indicate an error is to
throw an exception.
Previous Comments:
------------------------------------------------------------------------
[2007-11-28 23:57:14] r dot wilczek at web-appz dot de
Description:
------------
Documentation says PDO::prepare() returns FALSE on failure.
But tests with PDO_SQLITE and PDO_MYSQL show that you either get a
PDOException thrown at you or a PDOStatement which cannot be executed.
I am quite surprised, for I upgraded from PHP5.2.0 to PHP5.2.5. In
5.2.0 both drivers threw exceptions on syntax-errors in PDO::prepare().
One could live with exceptions instead of FALSE but it should be done
in a uniform manner of all the drivers.
Reproduce code:
---------------
$pdo = new PDO('mysql:host=localhost;dbname=test',
'user', 'password',
array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
$stmt = $pdo->prepare('some nonsense');
var_dump($stmt);
$pdo = new PDO('sqlite:/tmp/foo.db',
'user', 'password',
array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
$stmt = $pdo->prepare('some nonsense');
var_dump($stmt);
Expected result:
----------------
bool(false)
bool(false)
Actual result:
--------------
object(PDOStatement)#2 (1) {
["queryString"]=>
string(13) "some nonsense"
}
Fatal error: Uncaught exception 'PDOException' with message
'SQLSTATE[HY000]: General error: 1 near "some": syntax error' in
PHPDocument1:5
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=43443&edit=1