#45289 [NEW]: Cannot use prepared statements and fetch_row together
| From: | mike dot benza at rice dot edu | Date: | Tue, 17 Jun 2008 02:33:54 +0000 |
| Subject: | #45289 [NEW]: Cannot use prepared statements and fetch_row together | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-125819@lists.php.net to get a copy of this message | ||
From: mike dot benza at rice dot edu
Operating system: All
PHP version: 5.2.6
PHP Bug Type: MySQLi related
Bug description: Cannot use prepared statements and fetch_row together
Description:
------------
It's not possible (as far as I can tell) to use a prepared statement in
conjunction with mysqli_result::fetch_row or mysqli_result::fetch_assoc.
The inability to do it is not documented in the manual online.
There is no error given when you try to use fetch_row or fetch_assoc on a
result. In fact, it returns successfully, with garbage.
This is a similar issue as http://bugs.php.net/bug.php?id=42619&edit=2,
but there is still no documentation of the behavior and no error thrown
when trying to use fetch_row or fetch_assoc on a result from a prepared
statement
(Note: I only have 5.2.4, since that's the highest available on my OS. If
you really want me to upgrade, I'll build it from source, but I think you
know about this incompatibility, since it should be your primary use case;
mysqli should be able to combine the security of prepared statements with
the useful features of the old mysql extension)
(See also: http://www.robpoyntz.com/blog/?p=189,
which doesn't work, and I
haven't had a chance to figure out why)
(See also: http://blog.myhat.de/2007/06/26/pdo-and-extending-mysqli/)
Reproduce code:
---------------
$db = new mysqli(...);
$teamId = some integer;
$stmt = $db->prepare('SELECT * FROM teams where id=? LIMIT 1;');
if($stmt === FALSE) {
die("Could not prepare statement");
}
if($stmt->bind_param('i', $teamId) === FALSE) {
die("Could not bind params");
}
if($stmt->execute() === FALSE) {
die("Could not execute statement");
}
if(($result = $db->store_result()) === FALSE) {
die("Could not store result (db)." . $db->error);
}
$teamAsArray = $result->fetch_assoc();
print_r($teamAsArray);
Expected result:
----------------
I would expect the above code to have $teamAsArray be an associative array
with the fields in my team table as the keys, and the values be the
corresponding values. At the very least, I would expect an error to be
thrown since it can't.
I expect:
Array ( [id] => 1 [name] => Nicaragua II [updateTime] => 2008-06-05
00:35:43 [meetings] => Saturdays at 10:00pm in the Mech Lab [country] =>
Nicaragua [currentProjectId] => 3)
Actual result:
--------------
An array full of garbage...but not senseless garbage, but rather the
fields in the wrong spots, with some garbage mixed in between:
Array ( [id] => [name] => [updateTime] => ���
[meetings] => Nicaragua II [country] => �#+ [currentProjectId]
=> Saturdays at 10:00pm in the Mech Lab )
--
Edit bug report at http://bugs.php.net/?id=45289&edit=1
--
Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=45289&r=trysnapshot52
Try a CVS snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=45289&r=trysnapshot53
Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=45289&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=45289&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=45289&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=45289&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=45289&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=45289&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=45289&r=support
Expected behavior: http://bugs.php.net/fix.php?id=45289&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=45289&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=45289&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=45289&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=45289&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=45289&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=45289&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=45289&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=45289&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=45289&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=45289&r=mysqlcfg