This is a Singleton PHP wrapper that utilizes the PHP MySQLi class. It is meant to be non persistant, e.g., You must connect, perform the queries you need and then disconnect when you're finished.
Database::connect()
- Connects to the databaseDatabase::disconnect()
- Disconnects from the databaseDatabase::query()
- Performs an "advanced" query and gets the results if neededDatabase::get()
- Gets information from the databaseDatabase::where()
- Specifies a where clause for the action you perform.Database::update()
- Updates information from the databaseDatabase::delete()
- Deletes information from the databaseDatabase::insert()
- Inserts information into the databaseDatabase::instance()
- Gets the once-instantiated instance of this classDatabase::num_rows()
- Gets the number of rows forDatabase::get()
command without actually returning the dataDatabase::switch_database()
- Switches to a different database
Inserting some data into a table:
$data = array( 'foo' => 'bar' );
Database::connect();
Database::where( 'foobar', true );
Database::insert( 'my_table', $data );
Database::disconnect();
Removing data from a table:
Database::connect();
Database::where( 'foobar', true );
Database::where( 'foo', 'bar' );
Database::delete( 'my_table' );
Database::disconnect();
Getting data from a table:
Database::connect();
Database::where( 'foobar', true );
$records = Database::get( 'my_table' );
Database::disconnect();
Advanced Query:
Database::connect();
$records = Database::query( 'SELECT * FROM foo WHERE foobar = true AND foo IN ( SELECT bar FROM foo_db WHERE foo = 'bar' );' );
Database::disconnect();