php.net |  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
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
34 - 14 = ?
Subscribe to this entry?

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

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:
---------------
<?php   
error_reporting(E_ALL);

$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:

Prepare
errorcode=00000
errorinfo=array(1) { [0]=> string(5) "00000" }
Execute
return value of execute(): 'bool(false) '
errorcode=00000
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:

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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-02-26 20:20 UTC] wez@php.net
Sorry John, won't change this.  It's better to fail early where possible.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 12:01:31 2024 UTC