fluteflute Posted April 1, 2008 Share Posted April 1, 2008 I wrote the following functions to get data from a database. In particular they return data as an array.The first works fine but the second gives me errors about allowed memory size. I googled this and found how to increase the available memory. However this is a small table with around eight columns and only four rows so far. I am concerned for far bigger tables I would need lots of memory. Is there a better way of doing this? Code causing message: $data = database_getAllRows('users'); Functions: function database_getRow($table, $column, $searchValue) { include('settings.php'); $cxn = mysqli_connect($database_host, $database_user, $database_password, $database_name) or die ("Coudn't connect to server."); $query = "SELECT * FROM $table WHERE $column='$searchValue'"; $result = mysqli_query($cxn, $query) or die ("<p>Couldn't execute query."); while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) { return $row; // returns array of row from database } } function database_getAllRows($table) { include('settings.php'); $cxn = mysqli_connect($database_host, $database_user, $database_password, $database_name) or die ("Coudn't connect to server."); $query = "SELECT * FROM $table"; $result = mysqli_query($cxn, $query) or die ("<p>Couldn't execute query."); while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)!=='NULL') { $array[] = $row; // creates multidimesnional array of all rows from database } return $array; } Link to comment https://forums.phpfreaks.com/topic/99015-putting-an-entire-database-into-an-array/ Share on other sites More sharing options...
unsider Posted April 1, 2008 Share Posted April 1, 2008 Have you looked into SQL pagination: LIMIT, etc..? If not, I suggest looking into it. Much quicker relying on mySQL (faster than PHP). Then just include all tables/data, output it, then LIMIT it. Link to comment https://forums.phpfreaks.com/topic/99015-putting-an-entire-database-into-an-array/#findComment-506654 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.