473,466 Members | 1,368 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

In memory database

Anyone know of an extension that is 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. Then to be able to do simple select, insert, deletes and
updates.

This could be easier than using arrays for certain tasks.

Something like this would be nice. E.g.

$db->new memDB('myDB');
$tbl=new memTBL('names')
$tbl->addCol('fname','CHAR',20);
$tbl->addCol('lname','CHAR',20);
$tbl->addCol('dob','DATE');
$tbl->addKey('fname');
$tbl->addKey('lname','fname');
$db->addTable($tbl);

$db->exec("insert into names ('fname',lname','dob') values
('John','Doe','1/1/1900')");
$db->exec("select * from names where fname='John' order by lname");

Thanks

Jun 20 '06 #1
5 5986
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
Jun 20 '06 #2
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


Jun 20 '06 #3

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


You could use the memory (heap) storage engine in MySQL. You could also
store everything in variables/arrays and do a search in that.

Jun 20 '06 #4

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.

Jun 20 '06 #5
>
$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.


Good one. Now I have to fix it to do ascending, descending and up to 3
columns. I was trying to avoid this callback, but I may have no choice.
No one said life was easy.

Jun 20 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Mike P | last post by:
I know everything about reference counting and making sure you don't have large objects lying around. I have also profiled my app with multiple tools. I know about the fact GC collects memory but...
12
by: Jeremy | last post by:
Hi all, I'm getting very confused about how DB2 uses shared memory and I wonder if someone could clarify matters for me, please ? We are running 32bit DB2 V7.2 FP9 under AIX 4.3.3 on a machine...
5
by: Jim | last post by:
Hello, I have a broken server that we are going to be moving off to a new server with a new version of DB2 but here is what I have right now: RedHat 7.0 (2.2.24smp) DB2 v6.1.0.40 I am...
22
by: xixi | last post by:
hi, we are using db2 udb v8.1 for windows, i have changed the buffer pool size to accommadate better performance, say size 200000, if i have multiple connection to the same database from...
4
by: xixi | last post by:
i have a very serious memory problem, we have db2 udb v8.1 load on a HP titanium machine with 4 G memory, it is 64bit machine, currently on DB2 instance , i have three databases, but only one is...
7
by: Jon Trickey | last post by:
We migrated to 8.1 from 7.2 this weekend. Everything ran ok over the weekend, but we have a light user load then (about 200 users.) Today when we had close to 600 users connecting and running...
2
by: mghale | last post by:
Greetings, I have moved a database from the DB2 Windows Platform (Dev) to our production AIX Server and am experiencing an issue: The AIX platform is 5.3 and DB2 version 8.1 pixpack 9a...
3
by: thomas.porschberg | last post by:
Hi, I want to read records from a database and export it in an arbitrary format. My idea was to feed a class with a String array fetched from the database and let this class fire SAX events as...
26
by: Bill Reid | last post by:
Bear with me, as I am not a "professional" programmer, but I was working on part of program that reads parts of four text files into a buffer which I re-allocate the size as I read each file. I...
0
by: salman | last post by:
Hello We are working on an stock market application to buy and sell stock market shares. Clients are connected through local lan, we are easily maintaining and updating the client database when...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.