In memory database

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • ImOk

    #1

    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

  • Tim Martin

    #2
    Re: In memory database

    ImOk wrote:[color=blue]
    > Anyone know of an extension that is an in memory database?[/color]

    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.
    [color=blue]
    > 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.[/color]

    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

    Comment

    • ImOk

      #3
      Re: In memory database

      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+a ge and get a subset of anyone over
      40 possibly ascending or descending?

      E.g.
      $arr[0]=array('M',2000 0,20,'JOHN');
      $arr[1]=array('F',2200 0,24,'JANE');
      $arr[2]=array('M',3200 0,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:[color=blue]
      > ImOk wrote:[color=green]
      > > Anyone know of an extension that is an in memory database?[/color]
      >
      > 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.
      >[color=green]
      > > 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.[/color]
      >
      > 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[/color]

      Comment

      • Sjoerd

        #4
        Re: In memory database


        ImOk wrote:[color=blue]
        > Anyone know of an extension that is an in memory database?[/color]

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

        Comment

        • ZeldorBlat

          #5
          Re: In memory database


          ImOk wrote:[color=blue]
          > 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+a ge and get a subset of anyone over
          > 40 possibly ascending or descending?
          >
          > E.g.
          > $arr[0]=array('M',2000 0,20,'JOHN');
          > $arr[1]=array('F',2200 0,24,'JANE');
          > $arr[2]=array('M',3200 0,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:[color=green]
          > > ImOk wrote:[color=darkred]
          > > > Anyone know of an extension that is an in memory database?[/color]
          > >
          > > 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.
          > >[color=darkred]
          > > > 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.[/color]
          > >
          > > 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[/color][/color]

          $arr[0]=array('M',2000 0,20,'JOHN');
          $arr[1]=array('F',2200 0,24,'JANE');
          $arr[2]=array('M',3200 0,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.

          Comment

          • ImOk

            #6
            Re: In memory database

            >[color=blue]
            > $arr[0]=array('M',2000 0,20,'JOHN');
            > $arr[1]=array('F',2200 0,24,'JANE');
            > $arr[2]=array('M',3200 0,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.[/color]

            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.

            Comment

            Working...