Bug #52248 [NEW]: PDO::prepare() never return false on failure
| From: | l dot declercq at nuxwin dot com | Date: | Mon, 05 Jul 2010 05:29:36 +0000 |
| Subject: | Bug #52248 [NEW]: PDO::prepare() never return false on failure | ||
| Groups: | php.doc.bugs | ||
| Request: | Send a blank email to doc-bugs+get-4649@lists.php.net to get a copy of this message | ||
From:
Operating system: Linux (Debian Lenny
PHP version: Irrelevant
Package: Documentation problem
Bug Type: Bug
Bug description:PDO::prepare() never return false on failure
Description:
------------
hello everyone ;
I have found the following closed ticket:
http://bugs.php.net/bug.php?id=43443&thanks=3
but:
In the current documentation
(http://www.php.net/manual/en/pdo.prepare.php), I see the following about
error handling:
....................
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).
....................
So, normally, If I don't use Exception for error handling, I should test
the returned value of the PDO::prepare() method. On failure, I should get
FALSE. The problem is that currently, this method never returns FALSE on
failure but a PDOStatement object that can't be executed.
Also, normally , if an error occur during Sql statement preparation, I
should fetch error from PDO object and not from the PDOStatement object but
currently, I have not error reported from the PDO object:
$db->errorInfo()
Array
(
[0] => 00000
)
The error information are in the PDOStatement :
Array
(
[0] => 42000
[1] => 1064
[2] => You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near
'Something' at line 1
)
So, in my opinion, the current documentation for PDO::prepare() method is
wrong!
Thank
Note: Sorry for my poor English, I'm French.
Test script:
---------------
$stmt = $db->prepare('something');
if($stmt == FALSE) {
echo 'An error occured!';
} else {
echo 'I love PHP';
}
Expected result:
----------------
An error occurred!
Actual result:
--------------
I love PHP
And the content of the $stmt var:
PDOStatement Object
(
[queryString] => Something
)
--
Edit bug report at http://bugs.php.net/bug.php?id=52248&edit=1
--
Try a snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=52248&r=trysnapshot52
Try a snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=52248&r=trysnapshot53
Try a snapshot (trunk): http://bugs.php.net/fix.php?id=52248&r=trysnapshottrunk
Fixed in SVN: http://bugs.php.net/fix.php?id=52248&r=fixed
Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=52248&r=needdocs
Fixed in release: http://bugs.php.net/fix.php?id=52248&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=52248&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=52248&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=52248&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=52248&r=support
Expected behavior: http://bugs.php.net/fix.php?id=52248&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=52248&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=52248&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=52248&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=52248&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=52248&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=52248&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=52248&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=52248&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=52248&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=52248&r=mysqlcfg