|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #56301 Prepare() error handling inconsistent between drivers
Submitted: 2005-02-15 03:23 UTC Modified: 2005-02-26 20:20 UTC
From: jlim at natsoft dot com Assigned:
Status: Not a bug Package: PDO (PECL)
PHP Version: 5_0 CVS-2005-02-15 (dev) OS: Windows XP SP2
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: jlim at natsoft dot com
New email:
PHP Version: OS:


 [2005-02-15 03:23 UTC] jlim at natsoft dot com

In mysql and pgsql, when an illegal SQL stmt is passed into prepare(), a valid $stmt is returned. But in sqlite, false is returned.

I would suggest the prepare() failure detection be postponed to execute() for all code to ensure consistency. This is what ADOdb does.

Regards, John Lim

Reproduce code:

$connstr = 'mysql:dbname=test'; $u = 'root'; $p = 'xxx';
#$connstr = "pgsql:dbname=test";$u = 'test'; $p = 'xxx';
#$connstr = 'sqlite:' . getenv('HOME') . "/.web-watch.sql3";
$db = new PDO($connstr,$u,$p);

echo "<h3>Prepare</h3>";
$st2 = $db->prepare("selectx abc from nosuchtable ");
echo "errorcode=",$db->errorCode(),"<br>";
echo "errorinfo="; var_dump($db->errorInfo()); echo "<br>";

if ($st2) {
	echo "<h3>Execute</h3>";
	$ok = $st2->execute();

	echo "return value of execute(): '"; var_dump($ok); echo "'<br>";
	echo "errorcode=",$db->errorCode(),"<br>";
	echo "errorinfo="; var_dump($db->errorInfo()); echo "<br>";
} else
	echo "Statement not created<br>";

Expected result:
Output for mysql:

errorinfo=array(1) { [0]=> string(5) "00000" }
return value of execute(): 'bool(false) '
errorinfo=array(3) { [0]=> string(5) "00000" [1]=> int(1064) [2]=> string(175) "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 'selectx abc from nosuchtable' at line 1" } 

Actual result:
Output for sqlite:

errorinfo=array(3) { [0]=> string(5) "HY000" [1]=> int(1) [2]=> string(28) "near "selectx": syntax error" }
Statement not created


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2005-02-26 20:20 UTC]
Sorry John, won't change this.  It's better to fail early where possible.
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Fri May 14 00:01:23 2021 UTC