I want to save the contents of a specific database into an array, grouped by their primary keys. (Instead of the useless PDO method, fetchAll () organizes them).
My current code is:
$DownloadsPDO = $database->dbh->prepare("SELECT * FROM 'downloads'");
$DownloadsArray = $DownloadsPDO->execute();
$DownloadsArray = $DownloadsPDO->fetchAll();
Which then outputs:
Array ( [0] => Array ( [id] => 0 [0] => 0 [path] => /xx-xx/testfile.zip [1] => /xx-xx/testfile.zip [name] => Test Script [2] => Test Script [status] => 1 [3] => 1 ) [1] => Array ( [id] => 1 [0] => 1 [path] => /xx-xx/test--file.zip [1] => /xxxx/testfile.zip [name] => New Script-UPDATE [2] => New Script-UPDATE [status] => 1 [3] => 1 ) )
I was going to use PDO::FETCH_PAIR, but very soon I will increase the amount of data that I want to use in this scenario. This currently works, but when I start to increase the number of downloads and more and more clients come into the game, obviously the way of grouping the data causes a problem.
Can I group each array by primary key (i.e. identifier)?
source
share