tell me what it needs and what needs to be added or changed...
class DBO{
const ERR_SILENT = 0;
const ERR_WARNING = 1;
const ERR_EXCEPTION = 2;
const FETCH_ASSOC = 3;
const FETCH_BOTH = 4;
const FETCH_OBJ = 5;
const FETCH_NUM = 6;
const FETCH_CLASS = 7;
const PARAM_STR = 8;
const PARAM_NULL = 9;
const PARAM_INT = 10;
const PARAM_BOOL = 11;
const PARAM_LOB = 12;
private $_error_mode = 2;
private $_error_last = '';
private $_query_last = '';
private $_results_last = '';
private $_affected_rows = 0;
private $_columns_count = 0;
private $_query_count = 0;
private $_results_count = 0;
private $_statements = array();
private $_connect_persitent = false;
/**
*
* @param $driver: the name of the supported driver type
* @param $dbname: the name of your database
* @param $server: the server your database is hosted on, most of the time it is localhost
* @param $user: your database username used to login to your database
* @param $pass: your database password used to login to your database
* @example $db = new DBO('mysql' , 'your_database_name' , 'localhost' , 'your_username' , 'your_password');
*
**/
public function __construct($driver = '' , $dbname = '' , $server = '' , $user = '' , $pass = ''){
$this->_params = array($driver , $dbname , $server , $user , $pass);
foreach($this->_params as $params){
if(!is_string($params)){
if($this->_error_mode === 0){
return false;
}elseif($this->_error_mode === 1){
trigger_error('Argument Error: seems one or more of the supplied arguments is not a '
.'string type only string types are expected by DB __construct. File:');
}else{
throw new DBO_Exception('Argument Error: seems one or more of the supplied arguments is not a '
.'string type only string types are expected by DB __construct. File:');
}
}
}
$this->connect($this->_params[0], $this->_params[1], $this->_params[2],$this->_params[3],$this->_params[4]);
}
/**
*
* @param $driver: the name of the supported driver type
* @param $dbname: the name of your database
* @param $server: the server your database is hosted on, most of the time it is localhost
* @param $user: your database username used to login to your database
* @param $pass: your database password used to login to your database
* @example $db = new DBO('mysql' , 'your_database_name' , 'localhost' , 'your_username' , 'your_password');
*
**/
protected function connect($driver , $dbname , $server , $user , $pass){
if(strtolower($driver) === 'mysql'){
try{
$this->_lid = new PDO($driver.':host='.$server.';dbname='.$dbname , $user , $pass);
}catch(PDOException $pdo_error){
if($this->_error_mode === 0){
return false;
}elseif($this->_error_mode === 1){
trigger_error('Database Error: '. $pdo_error->getMessage());
$this->_error_last = array(
'message' => $pdo_error->getMessage() ,
'file' => $pdo_error->getFile(),
'line' => $pdo_error->getLine(),
);
}else{
throw new DBO_Exception('Database Error: '. $pdo_error->getMessage());
}
}
}elseif(strtolower($driver) === 'pgsql'){
try{
$this->_lid = new PDO($driver.':dbname='.$dbname.';host='.$server, $user , $pass);
}catch(PDOException $pdo_error){
if($this->_error_mode === 0){
return false;
}elseif($this->_error_mode === 1){
trigger_error('Database Error: '. $pdo_error->getMessage());
}else{
throw new DBO_Exception('Database Error: '. $pdo_error->getMessage());
}
}
}elseif(strtolower($driver) === 'sqlite'){
try{
$this->_lid = new PDO($driver.':dbname='.$dbname);
}catch(PDOException $pdo_error){
if($this->_error_mode === 0){
return false;
}elseif($this->_error_mode === 1){
trigger_error('Database Error: '. $pdo_error->getMessage());
}else{
throw new DBO_Exception('Database Error: '. $pdo_error->getMessage());
}
}
}
return $this->_lid;
}
/**
* @param $statement: the query string
* @param $params: the input parameters you can pass to the statement
* @example $db->query("SELECT column FROM table WHERE column = :something" , array(":something" => "7"));
* @example $db->query("SELECT column FROM table WHERE column = ?" , array("7"));
*
**/
public function query($statement = '' , array $params = array()){
if(count($params) > 0){
return $this->prepare($statement)->execute($params);
}else{
return $this->prepare($statement)->execute();
}
return false;
}
/**
* @param $statement: the name of the supported driver type
* @example $db->prepare("SELECT column FROM table")->execute();
* @example $db->prepare("SELECT column FROM table WHERE column = ?")->execute(array('name'));
*
**/
public function prepare($statement = ''){
if(!is_string($statement)){
if($this->_error_mode === 0){
return false;
}elseif($this->_error_mode === 1){
trigger_error('Argument Error: prepare expects only a string type');
}else{
throw new DBO_Exception('Argument Error: prepare expects only a string type');
}
}
$this->_query_count++;
$qid = $this->_query_count;
$transaction = $this->_lid->prepare($statement);
$this->_statements[$qid] = $transaction;
return $this;
}