Doc #79800 [Asn->Csd]: Wrong documented

From: Date: Tue, 07 Jul 2020 07:23:24 +0000
Subject: Doc #79800 [Asn->Csd]: Wrong documented
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-17692@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=79800&edit=1 ID: 79800 User updated by: behling at mumbomedia dot de Reported by: behling at mumbomedia dot de Summary: Wrong documented -Status: Assigned +Status: Closed Type: Documentation Problem Package: MySQLi related PHP Version: Irrelevant Assigned To: cmb Block user comment: N Private report: N New Comment: My fault. The function only retrieve one row. So if you want to get all rows, you have to call it in a loop. Something like this: while($row = $result->fetch_array(MYSQLI_ASSOC)){ $row2[] = $row; } Previous Comments: ------------------------------------------------------------------------ [2020-07-07 07:06:02] behling at mumbomedia dot de Alright here the snippet <?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"; // So this could return up to 3 rows $result = $mysqli->query($query); /* numeric array */ $row = $result->fetch_array(MYSQLI_NUM); // The resulting array is something like array('Germany','DE','USA','US','Great Britain','EN'); printf ("%s (%s)\n", $row[0], $row[1]); /* associative array */ $row = $result->fetch_array(MYSQLI_ASSOC); // $row should look like this array(array('Name'=>'Germany','CountryCode'=>'DE'),array('Name'=>'USA','CountryCode'=>'US'),array('Name'=>'Great Britain','CountryCode'=>'EN')); printf ("%s (%s)\n", $row[0]["Name"], $row[0]["CountryCode"]); /* associative and numeric array */ $row = $result->fetch_array(MYSQLI_BOTH); printf ("%s (%s)\n", $row[0][0], $row[0]["CountryCode"]); /* free result set */ $result->free(); /* close connection */ $mysqli->close(); ?> ------------------------------------------------------------------------ [2020-07-06 14:43:18] cmb@php.net > It fetchs the entire result set. It is not supposed to. Please provide a minimal self-contained reproduce script which shows that behavior. Thanks! ------------------------------------------------------------------------ [2020-07-06 10:14:26] behling at mumbomedia dot de Description: ------------ --- From manual page: https://php.net/mysqli-result.fetch-array --- mysqli_fetch_array — Fetch a result row as an associative, a numeric array, or both That's not true. It fetchs the entire result set. This is also the different between mysqli_fetch_row or mysqli_fetch_assoc. ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=79800&edit=1

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