From: Operating system: Linux i386 PHP version: 5.3SVN-2011-02-15 (SVN) Package: PDO related Bug Type: Bug Bug description:PDO prepared statements using SQLite can't bind non-text values in expressions
Description: ------------ This report is an addition to / repost of the bug reported in #45259 from 2008. I replied on that one a few weeks ago but nobody seemed to take notice. This bug seems to also have been reported in bug #53475 (2010). It concerns: When using PDO with the SQLite backend and prepared SQL statements, it appears to be impossible to bind anything but a text or NULL value to a parameter. As a remark I would like to mention, binded values other than string and NULL types are cast to a string automatically. The bug is explained quite well in bug #45259. And I've added a patch only for the 5.3 branch as that has support for the PHP_PARAM_ZVAL type (which 5.2 lacks apparently). The current patch will not easily be backported to 5.2, I think. I've tested the patch below with the svn commit I could grab today (308350). It includes a couple of test cases which should cover the bug quite well. Test script: --------------- $dbase = new PDO('sqlite::memory:'); $stmt = $dbase->prepare('SELECT 1=? AS result'); $stmt->execute(array(1)); echo '(INT == BOUNDINT) = ', ($stmt->fetchColumn() == 1 ? 'true' : 'false'), PHP_EOL; $stmt = $dbase->prepare('SELECT "1"=? AS result'); $stmt->execute(array(1)); echo '(STRING == BOUNDINT) = ', ($stmt->fetchColumn() == 1 ? 'true' : 'false'), PHP_EOL; Expected result: ---------------- (INT == BOUNDINT) = true (STRING == BOUNDINT) = false Actual result: -------------- (INT == BOUNDINT) = false (STRING == BOUNDINT) = true -- Edit bug report at http://bugs.php.net/bug.php?id=54023&edit=1 -- Try a snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=54023&r=trysnapshot52 Try a snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=54023&r=trysnapshot53 Try a snapshot (trunk): http://bugs.php.net/fix.php?id=54023&r=trysnapshottrunk Fixed in SVN: http://bugs.php.net/fix.php?id=54023&r=fixed Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=54023&r=needdocs Fixed in release: http://bugs.php.net/fix.php?id=54023&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=54023&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=54023&r=needscript Try newer version: http://bugs.php.net/fix.php?id=54023&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=54023&r=support Expected behavior: http://bugs.php.net/fix.php?id=54023&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=54023&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=54023&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=54023&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=54023&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=54023&r=dst IIS Stability: http://bugs.php.net/fix.php?id=54023&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=54023&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=54023&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=54023&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=54023&r=mysqlcfg