|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2005-02-26 20:20 UTC] wez@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Dec 13 15:00:01 2025 UTC |
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