PEAR is archived and read-only

This mirror preserves historical PEAR package releases and metadata so existing references remain available.

Home » Database » MDB2 » Bug #10181

Invalid type passed to prepare() results in crypt error

Details

Submitted2007-02-25 16:36 UTC
Frommercurious at dnr dot servegame dot org
Assignedquipo
StatusClosed
PackageMDB2
PHP Version5.2.1
OSFreeBSD
Roadmaps(Not assigned)

Comments

[2007-02-25 16:36 UTC] mercurious at dnr dot servegame dot org

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