Req #80844 [Com]: Array destructuring for mysqli_result

From: Date: Mon, 08 Mar 2021 10:07:57 +0000
Subject: Req #80844 [Com]: Array destructuring for mysqli_result
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-232618@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=80844&edit=1 ID: 80844 Comment by: rtrtrtrtrt at dfdfdfdf dot dfd Reported by: olafvdspek at gmail dot com Summary: Array destructuring for mysqli_result Status: Not a bug Type: Feature/Change Request Package: MySQLi related Operating System: * PHP Version: Irrelevant Block user comment: N Private report: N New Comment: RTFM https://www.php.net/manual/en/mysqli-result.fetch-array.php resulttype This optional parameter is a constant indicating what type of array should be produced from the current row data. The possible values for this parameter are the constants MYSQLI_ASSOC, MYSQLI_NUM, or MYSQLI_BOTH. By using the MYSQLI_ASSOC constant this function will behave identically to the mysqli_fetch_assoc(), while MYSQLI_NUM will behave identically to the mysqli_fetch_row() function. The final option MYSQLI_BOTH will create a single array with the attributes of both. Previous Comments: ------------------------------------------------------------------------ [2021-03-08 10:01:34] olafvdspek at gmail dot com // mysqli Array ( [uid] => 1 [name] => Alpha ) // PDO Array ( [uid] => 1 [0] => 1 [name] => Alpha [1] => Alpha ) ------------------------------------------------------------------------ [2021-03-07 23:31:32] requinix@php.net And what is the value of $row? What output do you see? ------------------------------------------------------------------------ [2021-03-07 23:10:47] olafvdspek at gmail dot com Not sure what you're trying to say, I'm aware as $row works.. This is a request for array destructuring to be supported too, like it is with PDO. ------------------------------------------------------------------------ [2021-03-07 23:00:44] requinix@php.net Hint: foreach ($mysqli->query("select uid, name from users") as $row) print_r($row); ------------------------------------------------------------------------ [2021-03-07 17:50:27] olafvdspek at gmail dot com Description: ------------ PDO supports this, it'd be nice if mysqli itself supported this as well. Test script: --------------- $mysqli = new mysqli('', 'pdo', '123', 'pdo'); foreach ($mysqli->query("select uid, name from users") as [$uid, $name]) // 3 print("$uid: $name\n"); Actual result: -------------- // PHP Warning: Undefined array key 0 on line 3 // PHP Warning: Undefined array key 1 on line 3 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=80844&edit=1

« previous php.bugs (#232618) next »