Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 2.5.0b5

Bug #10181 Invalid type passed to prepare() results in crypt error
Submitted: 2007-02-25 16:36 UTC
From: mercurious at dnr dot servegame dot org Assigned: quipo
Status: Closed Package: MDB2 (version 2.3.0)
PHP Version: 5.2.1 OS: FreeBSD
Roadmaps: (Not assigned)    
Subscription  


 [2007-02-25 16:36 UTC] mercurious at dnr dot servegame dot org (mercurious)
Description: ------------ When a non-supported conversion type is passed to prepare, execute will fail with a cryptic error. Applies to mysqli.php driver, but might apply to more drivers. Test script: --------------- <?php $sql = 'SELECT COUNT(1) AS matches FROM items'; $sql .= ' WHERE item_name = ?'; $sth = $dbh->prepare( $sql, // yes this should be text array('string'), MDB2_PREPARE_RESULT ); if(PEAR::isError($sth)) { die("Statement couldn't be prepared"); } $sth->execute('foo'); ?> Patch: --- mysqli.php.orig Thu Feb 22 01:41:37 2007 +++ mysqli.php Sun Feb 25 17:22:10 2007 @@ -1433,7 +1433,23 @@ $value = $data; } } - $param_query = 'SET @'.$parameter.' = '.$this->db->quote($value, $type); + // This can return an error if the given type is invalid. + // Like, programmer made a typo in the type he passed, or the + // type is not supported by this backend. + // More elegantly, this should check $type against supported types + // before trying anything with it, but this works. + // <rant> + // We do wanna give the programmer some clue what's going on, rather + // then the cryptic: + // PHP Catchable fatal error: Object of class MDB2_Error could + // not be converted to string in + // /wherever/pear/MDB2/Driver/mysqli.php on line 1436 + // </rant> + $quoted = $this->db->quote($value, $type); + if( PEAR::isError($quoted) ) { + return $quoted; + } + $param_query = 'SET @'.$parameter.' = '.$quoted; $result = $this->db->_doQuery($param_query, true, $connection); if (PEAR::isError($result)) { return $result; Expected result: ---------------- Some clue to what is wrong. Ideally it should already fail when the statement is prepared, rather then when it's executed, cause in essence this statement handler isn't valid. Actual result: -------------- PHP Catchable fatal error: Object of class MDB2_Error could not be converted to string in /usr/local/share/pear/MDB2/Driver/mysqli.php on line 1436

Comments

 [2007-02-26 21:47 UTC] quipo (Lorenzo Alberton)
This bug has been fixed in CVS. If this was a documentation problem, the fix will appear on pear.php.net by the end of next Sunday (CET). If this was a problem with the pear.php.net website, the change should be live shortly. Otherwise, the fix will appear in the package's next release. Thank you for the report and for helping us make PEAR better.