Return a two-dimensional array from an SQL query

Is there a way to return a two-dimensional array from an SQL query? How..

"SELECT id, x, y, z FROM test"

.. and return it as id => x, y, z? I could make a loop and create a second array, but I assume that additional work that I may not have to do. Just not familiar with SQL right now.

+3
source share
3 answers

In PHP, SQL queries will only return result sets. Rows and columns.

You need another loop to process it into the array you are accessing. This is not a problem and should be part of your database shell if you use it often.

$result = mysql_query(...);
$aData = array();
while($row = mysql_fetch_assoc($result))
   $aData[$row['id']] = array($row['x'], $row['y'], $row['z']);
+6
source

- , .

, , . , , . , , . , SQL-, . PHP , , - , .

, PHP , .

+2

SQL 2D- - , . SELECT id, x, y, z FROM test, id, x, y z test. id x, y z, .

PHP, id x, y z, SELECT .

0

Source: https://habr.com/ru/post/1727158/


All Articles