So after a feable attempt at a DBA layer i took some advice and started a new DB layer with PDO and currently is my execute method i have the PDO methods of bindValue() and execute() but after a few checks on the query string i have concluded bindValue is not working with in my foreach loop. So currently im a seeking some advice on routes i could go or a good code example of a proper way to bind values.
// example usage $db->prepare('SELECT * FROM :table' , array(':table' => 'users'));
public function prepare($statement = '' , array $bind = array()){
if(!is_string($statement)){
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 prepare');
}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 prepare');
}
}
if(!is_array($bind)){
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');
}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');
}
}
$query = $this->_lid->prepare($statement);
$this->_query_count++;
$q_count = $this->_query_count;
$this->_statements[$q_count] = array($query , $bind);
return $this;
}
public function execute(){
if(isset($this->_statements) && is_array($this->_statements)){
$query = $this->_statements[$this->_query_count][0];
if(isset($this->_statements[$this->_query_count]) && is_array($this->_statements[$this->_query_count][1])){
if($this->_statements[$this->_query_count][1] > 0){
foreach($this->_statements[$this->_query_count][1] as $k => $v){
var_dump($k);
var_dump($v);
$query->bindValue($k , $v);
var_dump($query);
}
//var_dump($query);
return $query->execute();
}else{
//var_dump($query);
return $query->execute();
}
}
}else{
throw new DBO_Exception('Database Error: the prepared query was not prepaired properly');
}
return false;
}