Bug #52248 [Opn]: PDO::prepare() never return false on failure
| From: | l dot declercq at nuxwin dot com | Date: | Mon, 05 Jul 2010 07:03:04 +0000 |
| Subject: | Bug #52248 [Opn]: PDO::prepare() never return false on failure | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-4650@lists.php.net to get a copy of this message | ||
Edit report at http://bugs.php.net/bug.php?id=52248&edit=1
ID: 52248
User updated by: l dot declercq at nuxwin dot com
Reported by: l dot declercq at nuxwin dot com
Summary: PDO::prepare() never return false on failure
Status: Open
Type: Bug
Package: Documentation problem
Operating System: Linux (Debian Lenny
PHP Version: Irrelevant
New Comment:
Ok, you can close this thread.
In fact, it's because by default, PDO emulate the Prepared Queries. I
think you should adds an advertisement in the documentation about this
issue.
To resume, if you don't want use exception for error handling and get
FALSE on failure, just set the ATTR_EMULATE_PREPARES attribute to FALSE.
But, don't use that with Mysql server version prior 5.1.17 because the
Prepared queries can't be cached.
Sorry for my poor English, I'm french.
Previous Comments:
------------------------------------------------------------------------
[2010-07-05 07:29:35] l dot declercq at nuxwin dot com
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 this bug report at http://bugs.php.net/bug.php?id=52248&edit=1