mysqli ile database classı oluştururken hatalara göre işlem yapmak istiyorum.
query deki sql doğru ise düzgün bir şekilde verileri getiriyor fakat yanlış ise hep aynı hatayı döndürüyor.
ben istiyorum ki tablo adı yanlışsa sorgudaki tablo adı yanlış hatasını döndürsün böyle bir tablo yok notice'ını döndürsün.
kodlar aşağıdaki gibidir:
function executeSQL($query=null){
if($query==null){
$this->_return_val= false;
}
if(isset($query) || $query !=""){
$this->result =$this->_mysqli->query($query);
if(!$this->_mysqli->error)
{
if(preg_match("/^(insert|delete|update|replace|truncate|drop|create|alter|set)\s+/i",$query)){
if($this->result){
// Take note of the insert_id
if ( preg_match("/^(insert|replace)\s+/i",$query) )
{
$this->_insert_id = $this->_mysqli->insert_id;
}
$this->_return_val= true;
} else {
$this->_last_error= $this->result->error;
}
} else {
if(preg_match("/^(select)\s+/i",$query)){
if($this->result){
// Store Query Results
$num_rows=0;
while ( $row = @$this->result->fetch_object())
{
// Store relults as an objects within main array
$this->_results[$num_rows] = $row;
$num_rows++;
}
@$this->result->free_result();
$this->_return_val= true;
} else {
$this->_last_error = $this->result->error;
}
}
}
} else {
$this->_last_error = $this->result->error;
}
}
return $this->_return_val;
}function get_var($query = null, $y=0){
if ( $query )
{
// Execute sql query and return values.
if($this->executeSQL($query)){
// Extract var out of cached results based x,y vals
if ( $this->_results[$y] )
{
$values = array_values(get_object_vars($this->_results[$y]));
}
// If there is a value return it else return null
$this->_return_val = (isset($values[$y]) && $values[$y]!=='')?$values[$y]:null;
} else {
// return results last error
$this->_return_val = $this->_last_error;
}
}
return $this->_return_val;
}yardımcı olabilecek olan var mı ?