ID: 43443 User updated by: r dot wilczek at web-appz dot de 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: johannes New Comment:
I agree that the exception makes sense. Well, then either this is a documentation issue (PDO::prepare() never returns FALSE, as mentioned errorneously at http://www.php.net/manual/en/pdo.prepare.php). (At least I am not able to make it returning FALSE) Or PDO::prepare() has to catch PDOExceptions when calling the constructor of PDOStatement and silence them by returning FALSE. Previous Comments: ------------------------------------------------------------------------ [2008-05-22 20:31:19] [EMAIL PROTECTED] 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. ------------------------------------------------------------------------ [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
