Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,154,538 members, 7,823,351 topics. Date: Friday, 10 May 2024 at 09:01 AM

Flat-sql Database Engine - An Ultra-light Weight Database Engine - Webmasters - Nairaland

Nairaland Forum / Science/Technology / Webmasters / Flat-sql Database Engine - An Ultra-light Weight Database Engine (1431 Views)

How Can I Extract Binary Jpeg From A Sql Database? / Flat-sql - An Ultra-light Weight Database Engine :: Php Stuff / Can I Use Php With Ms Sql Database? (2) (3) (4)

(1) (Reply)

Flat-sql Database Engine - An Ultra-light Weight Database Engine by Nobody: 10:38pm On Feb 20, 2012
The FlatSQL package is a small but very poweful set of classes for database like access to text “flat files”. It provides equivalents to many of the common SQL commands.
Below is an extended example of how to use Flatfile and the related classes. The example is a table that holds ‘posts’ (such as a message on a message board), each with an ID, the title, the date, the author and the text of the post.
This package does not require MySQL or any database engine to run, it is entirely standalone and requires just PHP only to run.
Setup

Now we need to create the database object and set it up. In this example we are using a database called CMS. The database is created automatically if it does not exist.
require_once(‘ffdb/dbase.php’);
$db = new Flatsql();
$db->query(“use dbase cms”);


INSERT

To insert a row, use the following sql statements. An autoincrement ID is generated by default. And oh, there is no create table function, table is created automatically if it does not already exist. The return value is the newly generated ID. Notice that the first field called uid is the auto-generated I.D - this is required be default.
$db->query(“insert into users(uid,first,last,city,phone) value(Null,’Anthony’,’Ogundipe’,’Lagos’,’08027034534’)”);
echo $db->newId; //latest id
SELECT

If you are familiar with MySQL or sql in general, then the commands below will not be new to you.
$row=$db->query(“select * from users”); //select all the data available
$row=$db->query(“select first,last from users”); //select first and lastname only
$row=$db->query(“select last,phone,first from users”);
$row=$db->query(“select first,last from users where city=’Lagos’ order by uid asc INTEGER_COMPARISON”); //ordering data
$row=$db->query(“select first,last from users where city=’Lagos’ order by first asc limit 1”); //limiting data returned
$row=$db->query(“select first,last from users where city=’Egbe’”); //where clause
$row=$db->query(“select first,last from users where uid=’2’”);
$row=$db->query(“select first,last from users where uid>’2’ and first=’Okon’”); //multiple conditions
$row=$db->query(“select first,last from users where city=’Lagos’ and phone=’070603223456’”);
$row=$db->query(“select first,last from users where city=’Lagos’ and phone=’08027034534’ ”);
$row=$db->query(“select first,last from users where city=’Lagos’ order by phone asc”);
$row=$db->query(“select first,last from users where city=’Lagos’ and phone=’08027034534’ order by phone asc”);
The result will be an array of arrays. You can loop through the associative arrays to get the individual data.

UPDATE

To update records stored in tables, you can use regular MySQL statements.
$db->query(“update users set last=’White’,city=’Broad Street’ where uid<’3’”);
$db->query(“update users set last=’White’ “); //this will update the entire column

DELETE RECORDS

MySQL delete statements are useful here also.
$db->query(“delete from users where uid=’1’”); //delete conditionally
$db->query(“delete from users”); //delete entire rows - truncate

DELETE TABLE

To delete an entire table and all the data it contains.
$db->query(“drop table users”);
TRUNCATE TABLE

To delete all the records stored inside a table.
$db->query(“truncate table users”);
COMBINING WITH FLAT FILE PACKAGE

You can use flat file commands concurrently as shown below. However, flatfile discussion is outside the scope of this tutorial.
$db = new Flatsql();
$db->query(“use dbase cms”);
$aSingleRow = $db->selectUnique(‘cms.txt’, 0, ‘2’);
var_dump($aSingleRow);

This is not a replacement for mysql o. I just made this just for the fun of it. . . .

Aye, you can find it on www.facebook.com/

(1) (Reply)

Newbie Questions Please Help senior members / Tips To Get An Approved Adsense Account For A Two Months Old Site/blog / Have I Been Hacked? (pics)

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 19
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.