#38546 [Fbk->Opn]: bindParam incorrect processing of bool types

From: Date: Tue, 22 Aug 2006 15:54:30 +0000
Subject: #38546 [Fbk->Opn]: bindParam incorrect processing of bool types
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-101125@lists.php.net to get a copy of this message
ID: 38546 User updated by: selecter at gmail dot com Reported By: selecter at gmail dot com -Status: Feedback +Status: Open Bug Type: PDO related Operating System: Gentoo Linux x86_64 PHP Version: latest snapshot New Comment: 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'; } ?> Previous Comments: ------------------------------------------------------------------------ [2006-08-22 15:13:16] tony2001@php.net If you're still able to reproduce it with the latest 5.2 snapshot (several changes were applied yesterday), please provide SHORT and COMPLETE reproduce script ("complete" means no missing tables, no missing variables etc.). A gdb backtrace would be also helpful. ------------------------------------------------------------------------ [2006-08-22 15:11:32] tony2001@php.net Please try using this CVS snapshot: http://snaps.php.net/php5.2-latest.tar.gz For Windows: http://snaps.php.net/win32/php5.2-win32-latest.zip ------------------------------------------------------------------------ [2006-08-22 15:01:48] selecter at gmail dot com - changed incorrect summary ------------------------------------------------------------------------ [2006-08-22 15:00:09] selecter at gmail dot com Description: ------------ The code below leads to unclear error Fatal error: : in /var/www/localhost/htdocs/crash.php on line 33 But if I pass int values instead of bool, this code works fine. Instead of: 'show_email' => (bool) 1, 'show_smiles' => (bool) 1, Write: 'show_email' => 1, 'show_smiles' => 1, I noticed that because I get those values like this: 'show_email' => CheckBox::isOn('show_email'), 'show_smiles' => CheckBox::isOn('show_smiles'), which return bool values... Reproduce 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 ); $st = $db->prepare("UPDATE preferences 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'; } ?> ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=38546&edit=1

« previous php.bugs (#101125) next »