Welcome Guest, Not a member yet? Register   Sign In
Error Handling with very basic SQL query
#1

Hi Guys,

I have built this simple code which uses a specific database configuration and then runs SELECT query on the EMPLOYEE table.
This table has very huge database and I believe because of that, the db is throwing error. Which is fine.  
Below is my code. I have done the error handling code in this but it still throws attached error on browser. I want it to suppress throwing error on browser and catch it into variable so I can display it properly. Because I would like to use this code for an API server.

Ignore the part where the code is commented for $DB_MYSQL. That is for future use, I am going to switch database on specific occassions.

PHP Code:
$DB_MSSQL $this->load->database('mssql_db'TRUE);
$DB_MSSQL->db_debug FALSE;

//$DB_MYSQL = $this->load->database('mysql_db', TRUE);
//$DB_MYSQL->db_debug = FALSE;

$sql "SELECT * from EMPLOYEES";
$result  $DB_MSSQL->query($sql);

echo 
$sql.'<hr/>';

if(
$result){
 
$row $result->result_array();
 
 
$count=1;
 foreach(
$row as $record){
 echo 
"[ $count ] ";
 
var_dump($record);
 echo 
'<hr/>';
 
$count++;
 
 
ob_flush(); flush();
 }
}
else{
 
$error $DB_MSSQL->_error_message();
 
var_dump($error);

Reply


Messages In This Thread
Error Handling with very basic SQL query - by aslamdoctor - 04-21-2019, 08:05 AM



Theme © iAndrew 2016 - Forum software by © MyBB