#38546 [Com]: bindParam incorrect processing of bool types

From: Date: Tue, 06 Feb 2007 16:38:58 +0000
Subject: #38546 [Com]: bindParam incorrect processing of bool types
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-108495@lists.php.net to get a copy of this message
ID: 38546 Comment by: hans at velum dot net Reported By: selecter at gmail dot com Status: Assigned Bug Type: PDO related Operating System: Gentoo Linux x86_64 PHP Version: latest snapshot Assigned To: wez New Comment: This looks to be the same issue as: http://pecl.php.net/bugs/bug.php?id=9919 Previous Comments: ------------------------------------------------------------------------ [2007-02-06 16:35:47] hans at velum dot net I don't think that anyone said this was crashing. It certainly is a fatal error in that it doesn't work. And using PDO w/ Exception error mode will (should!) eventually result in a fatal error for the app that's using it. This is clearly a PDO bug. If any application that uses PDO has to check to see if MySQL is being used & then alter that type params passed to bindValue() then there is NO VALUE in having the small set of *abstracted* types that PDO does provide. ------------------------------------------------------------------------ [2006-08-22 16:59:46] tony2001@php.net First of all, there is no crash. Fatal error is the result of your trigger_error() call. PDOStatement::execute() fails because MySQL API doesn't support boolean parameters (though they can be "emulated" through PDO). I'm leaving this to the maintainer to decide. ------------------------------------------------------------------------ [2006-08-22 16:42:10] selecter at gmail dot com That's what you get: Fatal error: : in /tmp/1.php on line 66 That's all that matters... Instead of: 'show_email' => (bool) 1, 'show_smiles' => (bool) 1, Write: 'show_email' => 1, 'show_smiles' => 1, and the query will be executed successfully. ------------------------------------------------------------------------ [2006-08-22 16:29:14] tony2001@php.net I get: --- array(1) { [0]=> string(5) "00000" } Notice: Undefined property: PDO::$errorCode in /tmp/1.php on line 62 Notice: Undefined offset: 2 in /tmp/1.php on line 62 <pre></pre> Fatal error: : in /tmp/1.php on line 66 --- No crashes. valgrind doesn't show anything wrong there. ------------------------------------------------------------------------ [2006-08-22 15:54:30] selecter at gmail dot com Still reproducable. Here's the code: <?php try{ $dsn = 'mysql:host=localhost;dbname=test'; $db = new PDO($dsn, 'root', 'pass'); }catch(PDOException $e){ trigger_error($e->getMessage(), E_USER_ERROR); } $prefs = array( 'show_email' => (bool) 1, 'show_smiles' => (bool) 1, 'timezone_offset' => 0, 'messages_on_page' => 5, 'uid', 6 ); $query = "CREATE TABLE prefs( uid MEDIUMINT UNSIGNED NOT NULL, show_email BOOL NOT NULL, show_smiles BOOL NOT NULL, timezone_offset TINYINT NOT NULL, messages_on_page TINYINT UNSIGNED NOT NULL )"; $query = "INSERT INTO prefs VALUES(6, 1, 1, 0, 5)"; $db->exec($query); $st = $db->prepare("UPDATE prefs SET show_email=?, show_smiles=?, timezone_offset=?, messages_on_page=? WHERE uid=?"); $st->bindParam(1, $prefs['show_email'], PDO::PARAM_BOOL); $st->bindParam(2, $prefs['show_smiles'], PDO::PARAM_BOOL); $st->bindParam(3, $prefs['timezone_offset'], PDO::PARAM_INT); $st->bindParam(4, $prefs['messages_on_page'], PDO::PARAM_INT); $id = 6; $st->bindParam(5, $id, PDO::PARAM_INT); if(($num=$st->execute()) === FALSE){ $einfo = $db->errorInfo(); $einfo = $db->errorCode.': '.$einfo[2]; ?><pre><?php debug_print_backtrace(); ?></pre><?php trigger_error($einfo, E_USER_ERROR); }else{ echo 'ok'; } ?> ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at http://bugs.php.net/38546 -- Edit this bug report at http://bugs.php.net/?id=38546&edit=1

« previous php.bugs (#108495) next »