ID: 48373
Updated by: [email protected]
Reported By: jochen dot wiedmann at gmail dot com
Status: Bogus
Bug Type: MySQLi related
Operating System: Fedora Linux 10
PHP Version: 5.2.9
New Comment:
After removal of "or die()" for mysqli->use_result, PHP will tell you
that your script is borked:
nixnutz@ulflinux:~/src/login/php5> sapi/cli/php bar.php
Fatal error: Call to a member function fetch_row() on a non-object in
/home/nixnutz/src/login/php5/bar.php on line 23
nixnutz@ulflinux:~/src/login/php5> cat bar.php
<?php
$mysqli = mysqli_init();
$mysqli->real_connect("localhost", "root", root, 'test');
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
$mysqli->query("DROP TABLE IF EXISTS prep_and_fetch_row")
or die($mysqli->error);
$mysqli->query("CREATE TABLE prep_and_fetch_row(id BIGINT NOT NULL
PRIMARY KEY, name VARCHAR(64) NOT NULL)")
or die($mysqli->error);
$mysqli->query("INSERT INTO prep_and_fetch_row (id, name) VALUES (1,
'abc')")
or die($mysqli->error);
$stmt = $mysqli->prepare("SELECT * FROM prep_and_fetch_row WHERE
id=?")
or die($mysqli->error);
$id = "1";
$stmt->bind_param("i", $id) or die($mysqli->error);
$stmt->execute() or die($mysqli->error);
$result = $mysqli->use_result();
while ($row = $result->fetch_row()) {
print "----- result row -----------\n";
print_r($row);
}
print "----- no more results -----------\n";
$mysqli->query("DROP TABLE prep_and_fetch_row") or
die($mysqli->error);
$mysqli->close();
?>
... and PHP is right. With MySQL Prepared Statements you have to bind
results. There is no way in PHP 5.2.x to get a resultset object from a
statement.
Previous Comments:
------------------------------------------------------------------------
[2009-07-03 12:49:10] [email protected]
After removal of "or die()" for mysqli->use_result, PHP will tell you
that your script is borked:
nixnutz@ulflinux:~/src/login/php5> sapi/cli/php bar.php
Fatal error: Call to a member function fetch_row() on a non-object in
/home/nixnutz/src/login/php5/bar.php on line 23
nixnutz@ulflinux:~/src/login/php5> cat bar.php
<?php
$mysqli = mysqli_init();
$mysqli->real_connect("localhost", "root", root, 'test');
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
$mysqli->query("DROP TABLE IF EXISTS prep_and_fetch_row")
or die($mysqli->error);
$mysqli->query("CREATE TABLE prep_and_fetch_row(id BIGINT NOT NULL
PRIMARY KEY, name VARCHAR(64) NOT NULL)")
or die($mysqli->error);
$mysqli->query("INSERT INTO prep_and_fetch_row (id, name) VALUES (1,
'abc')")
or die($mysqli->error);
$stmt = $mysqli->prepare("SELECT * FROM prep_and_fetch_row WHERE
id=?")
or die($mysqli->error);
$id = "1";
$stmt->bind_param("i", $id) or die($mysqli->error);
$stmt->execute() or die($mysqli->error);
$result = $mysqli->use_result();
while ($row = $result->fetch_row()) {
print "----- result row -----------\n";
print_r($row);
}
print "----- no more results -----------\n";
$mysqli->query("DROP TABLE prep_and_fetch_row") or
die($mysqli->error);
$mysqli->close();
?>
... and PHP is right. With MySQL Prepared Statements you have to bind
results. There is no way in PHP 5.2.x to get a resultset object from a
statement.
------------------------------------------------------------------------
[2009-06-05 20:41:09] jochen dot wiedmann at gmail dot com
Ping?
------------------------------------------------------------------------
[2009-05-24 15:27:15] jochen dot wiedmann at gmail dot com
Description:
------------
This is a follow up to bug 45289, which has been closed due to missing
feedback. I have checked the latest snapshot (php5.2-200905151830),
whether the problem still persists by using the script below. (Should be
easy to derive a .phpt file from it.)
Reproduce code:
---------------
<?php
$mysqli = mysqli_init();
$mysqli->real_connect("localhost", "root", null, 'test');
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
$mysqli->query("DROP TABLE IF EXISTS prep_and_fetch_row")
or die($mysqli->error);
$mysqli->query("CREATE TABLE prep_and_fetch_row(id BIGINT NOT NULL
PRIMARY KEY, name VARCHAR(64) NOT NULL)")
or die($mysqli->error);
$mysqli->query("INSERT INTO prep_and_fetch_row (id, name) VALUES (1,
'abc')")
or die($mysqli->error);
$stmt = $mysqli->prepare("SELECT * FROM prep_and_fetch_row WHERE
id=?")
or die($mysqli->error);
$id = "1";
$stmt->bind_param("i", $id) or die($mysqli->error);
$stmt->execute() or die($mysqli->error);
$result = $mysqli->use_result() or die($mysqli->error);
while ($row = $result->fetch_row()) {
print "----- result row -----------\n";
print_r($row);
}
print "----- no more results -----------\n";
$mysqli->query("DROP TABLE prep_and_fetch_row") or
die($mysqli->error);
$mysqli->close();
?>
Expected result:
----------------
Expected output: Something like
----- result row -----------
Array
(
[0] => int(1)
[1] => string(3) "abc"
)
----- no more results -----------
Actual result:
--------------
Actual output:
----- result row -----------
Array
(
[0] =>
[1] =>
)
----- no more results -----------
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=48373&edit=1
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.