|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2009-05-24 15:27 UTC] 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 ----------- PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Nov 05 08:00:02 2025 UTC |
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.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.