Bug #12137 Updated: PEAR/DB : DB_common::executeEmulateQuery() bug
ID: 12137
Updated by: cox
Reported By: sav@tut.by
Old Status: Open
Status: Closed
Bug Type: Unknown/Other Function
Operating System:
PHP Version: 4.0.6
New Comment:
That was fixed in 11th July 2001. Thanks any way.
Previous Comments:
------------------------------------------------------------------------
[2001-07-13 05:34:53] sav@tut.by
Multiple execution emulation fails as in the following script:
<?php
$db = DB::connect("mysql://localhost/test");
$some_query_with_params = "DELETE FROM TST WHERE id = ? ";
$params = array(1,2,3);
$stmt = $db->prepare($some_query_with_params);
foreach($params as $param)
$db->execute($stmt, array($param)); //Fails !!!
?>
The reason for that is executeEmulateQuery() code:
function executeEmulateQuery($stmt, $data = false)
{
$p = &$this->prepare_tokens;
$stmt = (int)$this->prepare_maxstmt++; // BUG ?
if (!isset($this->prepare_tokens[$stmt]) ||
!is_array($this->prepare_tokens[$stmt]) ||
!sizeof($this->prepare_tokens[$stmt])) {
return $this->raiseError(DB_ERROR_INVALID);
}
$qq = &$this->prepare_tokens[$stmt];
// and so on...
What does the second line do?:
$stmt = (int)$this->prepare_maxstmt++;
It ignores the input parameter $stmt, sets it to some unreasonable value, and we always get
DB_ERROR_INVALID. If the line is removed - everything works. Apparently this line should not be here
at all.
------------------------------------------------------------------------
Edit this bug report at http://bugs.php.net/?id=12137&edit=1
Thread (2 messages)