From: Operating system: all PHP version: 5.3.3 Package: MySQLi related Bug Type: Bug Bug description:Binding params doesn't work when selecting a date inside a CASE-WHEN
Description: ------------ This is MySQL Bug #49406 Binding params doesn't work when selecting a date inside a CASE-WHEN Description: When querying a date field (must be type "date"!) inside a CASE-WHEN block, the result-binding fails (does return only empty or incorrect values for all selected fields), when using the prepare()/execute() API-functions. When using the query() API-function instead, it works as expected. Sample query: SELECT CASE WHEN 0 THEN CAST('2009-12-03' AS DATE) ELSE CAST('2009-12-03' AS DATE) END When skipping the CASE-WHEN and selecting the ELSE-value directly, it works always as expected (with both API-functions): SELECT CAST('2009-12-03' AS DATE) In summary, this three conditions must be true, to reproduce the problem: - Result-parameter binding using bind_result() must be used - one selected column using CASE-WHEN - the fields inside this CASE-WHEN must be from type date How to repeat: I reproduced this with PHP mysqli client, but I guess the root of the problem is independent from the client: <?php $query = 'SELECT CASE WHEN 0 THEN CAST(\'2009-12-03\' AS DATE) ELSE CAST(\'2009-12-03\' AS DATE) END'; $dbMysqli = new mysqli('host', 'username', 'password'); // via mysqli::query: $result = $dbMysqli->query($query); $rowViaMysqli = $result->fetch_row(); $valueViaMysqli = $rowViaMysqli[0]; echo "Fetched via mysqli::query():\n"; var_dump($valueViaMysqli); // Always correct output: // output: string(10) "2009-12-03" // via mysqli::prepare/execute: $stmt = $dbMysqli->prepare($query); $stmt->execute(); $stmt->store_result(); $valueViaMysqli = null; $stmt->bind_result($valueViaMysqli); $stmt->fetch(); echo "\nFetched via mysqli::prepare/execute/store_result/bind_result/fetch:\n"; var_dump($valueViaMysqli); // Different output on different clients/servers, but always wrong: // output on PHP 5.2/MySQL 5.1.37: null // output on PHP 5.3/MySQL 5.1.38: string(11) "12338-48-57" -- Edit bug report at http://bugs.php.net/bug.php?id=52745&edit=1 -- Try a snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=52745&r=trysnapshot52 Try a snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=52745&r=trysnapshot53 Try a snapshot (trunk): http://bugs.php.net/fix.php?id=52745&r=trysnapshottrunk Fixed in SVN: http://bugs.php.net/fix.php?id=52745&r=fixed Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=52745&r=needdocs Fixed in release: http://bugs.php.net/fix.php?id=52745&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=52745&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=52745&r=needscript Try newer version: http://bugs.php.net/fix.php?id=52745&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=52745&r=support Expected behavior: http://bugs.php.net/fix.php?id=52745&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=52745&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=52745&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=52745&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=52745&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=52745&r=dst IIS Stability: http://bugs.php.net/fix.php?id=52745&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=52745&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=52745&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=52745&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=52745&r=mysqlcfg