php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #46019 mysqli_result::fetch_array problem
Submitted: 2008-09-07 23:30 UTC Modified: 2008-10-01 11:12 UTC
From: nothinghere at gmx dot net Assigned:
Status: Not a bug Package: Documentation problem
PHP Version: Irrelevant OS: Linux
Private report: No CVE-ID: None
 [2008-09-07 23:30 UTC] 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            
)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-10-01 11:12 UTC] bjori@php.net
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.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri May 17 00:01:34 2024 UTC