cacio / php_database_class

A php database wrapper for mutiple types of database (e.g. MySQL, Firebird, Oracle and etc..)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

PHP Database Class

A collection of class of database to call different types of database in one class

How to use it

Get new instance like this

<?php
require 'Database.php';
$db = new Database('MySQL');

setting the connection configuration

$db->driver->connect('hostname', 'database', 'username', 'password');

Basic Methods

See below basic methods to call select, update, delete and query in the class.

Select

$db_column = array(
	'column1',
	'column2'
);
			  
$db_where = array(
	'search_column_name' => 'search_value'
);
			  
$db_order = array(
	'column_name_to_order' => 'desc'
);
			  
$db->driver->select('tablename', $db_column, $db_where, $db_order);

$db->driver->execute();

Update

$db_column = array(
	'column1' => 'column1_value',
	'column2' => 'column2_value'
);
			 
$db_where = array(
				'search_column_name' => 'search_value'
			)

$db->driver->update('tablename', $db_column, $db_where);

$db->driver->execute();

Delete

$db_where = array(
	'search_column_name' => 'search_value'
)

$db->driver->delete('tablename', $db_where);

$db->driver->execute();

Fetching Data

See below methods for different ways in fething data using php database class.

Fetch Row

$db_column = array(
	'column1',
	'column2'
);
			  
$db->driver->select('tablename', $db_column);

$db->driver->execute();

foreach($db->driver->fetch_row() as $value){
	echo $value[0];
	echo $value[1];
}

Fetch Associative

$db_column = array(
	'column1',
	'column2'
);
			  
$db->driver->select('tablename', $db_column);

$db->driver->execute();

foreach($db->driver->fetch_assoc() as $value){
	echo $value['column1'];
	echo $value['column2'];
}

Fetch Object

$db_column = array(
	'column1',
	'column2'
);
			  
$db->driver->select('tablename', $db_column);

$db->driver->execute();

foreach($db->driver->fetch_object() as $value){
	echo $value->column1;
	echo $value->column2;
}

Other Database class methods

see below other useful methods of PHP Database Class.

Closing connection

$db->driver->close();

Beginning transaction

$db->driver->begin_trans();

$db_where = array(
	'search_column_name' => 'search_value'
)

$db->driver->delete('tablename', $db_where);

$db->driver->execute();

$db->driver->commit();

Rollback transaction

$db->driver->rollback();

Commiting transaction

$db->driver->commit();

About

A php database wrapper for mutiple types of database (e.g. MySQL, Firebird, Oracle and etc..)


Languages

Language:PHP 100.0%