#46019 [Opn->Bgs]: mysqli_result::fetch_array problem

From: Date: Wed, 01 Oct 2008 11:12:21 +0000
Subject: #46019 [Opn->Bgs]: mysqli_result::fetch_array problem
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-1182@lists.php.net to get a copy of this message
ID: 46019 Updated by: bjori@php.net Reported By: nothinghere at gmx dot net -Status: Open +Status: Bogus Bug Type: Documentation problem Operating System: Linux PHP Version: Irrelevant New Comment: The examples demonstrate that you only get one row per call to mysqli_result::fetch_array() and after each call the "result pointer" is increased. Furthermore the example demonstrates you can get different return arrays depend on the argument you pass to it. Replace the example with a while() loop will not make it possible to demonstrate the different return arrays. Previous Comments: ------------------------------------------------------------------------ [2008-09-07 23:30:47] nothinghere at gmx dot net 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 ) ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=46019&edit=1

« previous php.doc.bugs (#1182) next »