|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2008-10-01 11:12 UTC] bjori@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Dec 03 20:00:01 2025 UTC |
Description: ------------ The output of the examples are slightly misleading because you can see 3 lines of output. The description of mysqli_result::fetch_array say that it will return only one row or NULL. But there is now while of for loop in the examples to put the three lines of the result in the array. That's why the code examples can't work and give only the last line of the result. Reproduce code: --------------- <?php $mysqli = new mysqli("localhost", "my_user", "my_password", "world"); /* check connection */ if (mysqli_connect_errno()) { printf("Connect failed: %s\n", mysqli_connect_error()); exit(); } $query = "SELECT Name, CountryCode FROM City ORDER by ID LIMIT 3"; $result = $mysqli->query($query); $row = $result->fetch_array(MYSQLI_ASSOC); print_r($row) $result->close(); $mysqli->close(); ?> Expected result: ---------------- Array ( [0] => Array ( [Name] => Kabul [CountryCode] => AFG ) [1] => Array ( [Name] => Qandahar [CountryCode] => AFG ) [2] => Array ( [Name] => Herat [CountryCode] => AFG ) ) Actual result: -------------- Array ( [Name] => Kabul [CountryCode] => AFG )