Menu

OOPSQL

OOPSQL (MySQLi Database Handler)

OOPSQL is automatically called by common.php when the define("DB_ENABLE", false); in config.php is set to on.

ie.

require_once(LOC_CLASSES."OOPSQL.class.php"); //Include OOPSQL MySQLi Database Handler
$dbo=OOPSQL::getInstance(); //Create MySQL DB Instance
$dbo->connect($cfg[LOC]["DB_HOSTNAME"], $cfg[LOC]["DB_USERNAME"], $cfg[LOC]["DB_PASSWORD"], $cfg[LOC]["DB_DATABASE"]); //Connect to DB and get Connection Object

Generic SQL can be called as follows:

//Custom SQL Query
$dbo->doQuery("SELECT * FROM people ORDER BY dob DESC");
while($ROW=$dbo->loadObjectList())
{
    echo("Firstname: $ROW[firstname] <br/>
    Surname: $ROW[surname]<br/>
    Nickname: $ROW[nickname]<br/>
    Date Of Birth: $ROW[dob]<br/>
    Hobbies: $ROW[hobbies]<hr/>");
}

OOPSQL (Object Oriented Programming SQL)
In order to objectify an SQL table in code the following must be setup beforehand:

Setup
1. Create [TABLENAME].class.php in includes/classes/oopsqltables folder (Where [TABLENAME] is the name of the MySQL Table)
2. Edit [TABLENAME].class.php (eg. people.class.php) and populate with Table Columns in this Format

<?php
//People DBT Class (Database Table Class)
class people extends table {
    var $id=NULL;
    var $firstname=NULL;
    var $surname=NULL;
    var $nickname=NULL;
    var $dob=NULL;
    var $hobbies=NULL;
    var $table="people";
}
?>
  1. Instantiate Table Class: require_once(LOC_DBTCLASSES."people.class.php");

Usage

Init Table Class

$people=new people();

Load And Display Single Record By ID

$people->load('1'); //Load Person with id 1 from people table
echo("Firstname: $people[firstname] <br/>
    Surname: $peoplepeople[surname]<br/>
    Nickname: $people[nickname]<br/>
    Date Of Birth: $people[dob]<br/>
    Hobbies: $people[hobbies]");

Insert New Record

$data=array("firstname"=>"Steven","surname"=>"Graham","nickname"=>"Stevie G","dob"=>"1981-10-01","hobbies"=>"Singing,XBOX");
$people->bind($data);
$people->store();

Update Existing Record

$people->load('1'); //Select User id 1 (Steven Graham)
$data=array("firstname"=>"Steven","surname"=>"Graham","nickname"=>"Stevie G","dob"=>"1981-10-01","hobbies"=>"Singing,XBOX,Snooker");
$people->bind($data);
$people->store();

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.