HomeBlogProjects

Other Projects


Simple DB

  • Description/Demo
  • Docs/Download
  • Discuss/Debug

A PHP5 class to allow the manipulation of a text file using SQL syntax.

This is something I wrote quite a while ago when I was working on a site that didn't have a database. Their intention was to get one later, so in order to make it easier to migrate over when they did, I treated the text files as if they were database tables and used sql syntax as closely as possible to extract information from it. It worked like a charm, and made switching much easier. I didn't need to do very complex stuff, and I always meant to support things like and/or in the where clause, but life got in the way, so I just migrated it to a PHP 5 class.

It would be easy enough to implement, and I'll do it if there is any interest in it.


To use it, you just need to put it on the server, and then call it from the script where you want the functionality.

include("YourPath/SimpleDB.php");

$db = new SimpleDB;

//Create a three column file
$db->query("create table myfile.inc (id, myvar1, myvar2)");

//Insert some values

  $db->query("insert into myfile.inc (1, First Value, Second value)");

  $db->query("insert into myfile.inc (2, Value, Any value)");

  $db->query("insert into myfile.inc (3, Hi there, Another value)");

//Update some values

  $db->query("update myfile.inc set myvar1 = Bye there, myvar2 = Some value where id = 3");

//Delete some values

  $db->query("delete from myfile.inc where id = 3");

//Select some values

  $db->query("select * from myfile.inc where id = 3");

  $db->query("select id, myvar1 from myfile.inc where id = 2");
Note: You do not need to quote strings
 
It can be downloaded here. Hope it's useful to somebody. Leave any feedback in the comments.

0 Comments

Post New Comment
Add comments here
Name:
Email:
URL:
Comment:BoldItalicUnderlineCreate linkCode BlockInsert Unordered List

JQuery/PHP Website and Applications Developer, based in Ireland.
Interests: Open Source Software, Supercomputers, Financial Markets, Sport, Science, Sustainable Energy. AGW Skeptic.

follow paulhan on twitter
Help me build a supercomputer