A collection of class of database to call different types of database in one class
Get new instance like this
<?php
require 'Database.php';
$db = new Database('MySQL');
setting the connection configuration
$db->driver->connect('hostname', 'database', 'username', 'password');
See below basic methods to call select, update, delete and query in the class.
$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();
$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();
$db_where = array(
'search_column_name' => 'search_value'
)
$db->driver->delete('tablename', $db_where);
$db->driver->execute();
See below methods for different ways in fething data using php database class.
$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];
}
$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'];
}
$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;
}
see below other useful methods of PHP Database Class.
$db->driver->close();
$db->driver->begin_trans();
$db_where = array(
'search_column_name' => 'search_value'
)
$db->driver->delete('tablename', $db_where);
$db->driver->execute();
$db->driver->commit();
$db->driver->rollback();
$db->driver->commit();