|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2008-05-22 20:31 UTC] uw@php.net
[2008-05-23 07:54 UTC] r dot wilczek at web-appz dot de
[2008-11-06 10:45 UTC] johannes@php.net
[2008-11-06 16:09 UTC] sean@php.net
[2008-11-07 14:45 UTC] vrana@php.net
[2010-07-05 07:19 UTC] l dot declercq at nuxwin dot com
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Nov 14 18:00:02 2025 UTC |
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