Re: In memory database




ImOk wrote:
Lets say I have an array of names, gender, age and salary that I read
from an Excel spreadsheet or CSV file.

How do I sort this by gender+salary+age and get a subset of anyone over
40 possibly ascending or descending?

E.g.
$arr[0]=array('M',20000,20,'JOHN');
$arr[1]=array('F',22000,24,'JANE');
$arr[2]=array('M',32000,40,'JOE');

I looked at using array_multisort but you have to jump through hoops it
seems. Maybe I am doing this wrong.

I am aware data will be lost of course when the program terminates. And
it can always be saved to a text file. Sometimes small databases are
much faster and easier being manipulated in memory especially if I dont
have to install a database engine.

Tim Martin wrote:
ImOk wrote:
Anyone know of an extension that is an in memory database?

I've never used it from PHP, but AIUI SQLite (www.sqlite.org) has a PHP
extension, and can be used to create an in-memory database.

I dont want to create any files on disk (nor install a database engine)
but have an object/variable that points to a database and tables all in
memory.

Why do you want to do this? What problem are you trying to solve? You
are aware that all data may be lost at the end of the script execution?

Tim

$arr[0]=array('M',20000,20,'JOHN');
$arr[1]=array('F',22000,24,'JANE');
$arr[2]=array('M',32000,40,'JOE');

function mySort($a1, $a2) {
foreach($a1 as $i => $val) {
if($a1[$i] < $a2[$i])
return -1;
if($a1[$i] > $a2[$i])
return 1;
}
return 0;
}

usort($arr, 'mySort');

Will sort it by the first "column", then the second, then the third,
etc.

.



Relevant Pages

  • Re: PHP/MySQL project
    ... > Looking to build a dynamic site using PHP/MySQL. ... > import changes to the database easily. ... Import the csv file into the MySql db, and then use phpmyadmin in the future ... The version of PHP will be important if you are considering finding / buying ...
    (alt.php)
  • Re: CSV(???)
    ... What csvline does is straightforward: ... into a csv file, the idea being that the office ... to a real database? ... The boss wanted me to use php because Python ...
    (comp.lang.python)
  • Re: [PHP] Pragmatically changing a "Record Number"
    ... Is there away with PHP that I can pragmatically change that value to ... the total records in the database more so then a representation of ... The main reason for changing it is I do currently have an option to sort by record number, although, if I add a Record number in php, but still have it sort based off of the record number stored in the database, it would still sort right, but also look right... ...
    (php.general)
  • Re: Exporting From MySQL to .csv using PHP
    ... I'm sort of new to PHP. ... I am using the following code to retrieve a ... This allows creates a .csv file, ... result from the database. ...
    (comp.lang.php)
  • Help with Data Tables
    ... I'm rewriting something I did initially in PHP / MySql on a ... vb.net / mysql platform. ... Data is loaded into the database with some changes ... Step one works fine -- data is saved to a csv file. ...
    (microsoft.public.dotnet.languages.vb)