0

I am writing rest apis in php, but the errors are thrown when there are some null values are inserted in the api.It shows the sql query into the response page, how do I stop it from being displayed, what is the best exception handling in this case.I am bit new to php, so any help is appreciated. Below is the sample code I write to query.

 $limit = " LIMIT ".$post_data['offset'].",".$post_data['limit']; $sql = "SELECT record_id from "; $shareResult= $this->db->query($sql)->result_array(); if(empty($shareResult[0]['record_id']) || $shareResult[0]['record_id'] != 0){ $query="SELECT *"; $result= $this->db->query($query); if($result->num_rows()>0){ $res1=$this->db->query($qry)->result_array(); $res[0]=$res1[0]; $res[1]=$result->result_array(); return $res; } }else if($shareResult[0]['record_id'] === 0){ return false; } 
8
  • Possible duplicate of How to get mysqli error in different environments? Commented Apr 28, 2017 at 8:56
  • Check this post - stackoverflow.com/a/1918628/4841755. It might be helpfull. Commented Apr 28, 2017 at 8:57
  • Ref this - php.net/manual/en/language.exceptions.php. Basically, you've to write your code like this - try { /* Place your code */ } catch (Exception $e) { echo 'Caught exception: ', $e->getMessage(), "\n"; } Commented Apr 28, 2017 at 8:57
  • It depends on the MySQL api you use in php to connect to MySQL. SO has dozens of question for each of them already. Commented Apr 28, 2017 at 8:59
  • I am using $this->db->query("Select *") to query the database. Commented Apr 28, 2017 at 9:01

1 Answer 1

1

if you are talking about Codeigniters default debug option you should take a closer look @your db config

Something like that should appear

$db['default'] = array( 'dsn' => '', 'hostname' => 'localhost', 'username' => 'root', 'password' => '', 'database' => 'database_name', 'dbdriver' => 'mysqli', 'dbprefix' => '', 'pconnect' => TRUE, 'db_debug' => TRUE, 'cache_on' => FALSE, 'cachedir' => '', 'char_set' => 'utf8', 'dbcollat' => 'utf8_general_ci', 'swap_pre' => '', 'encrypt' => FALSE, 'compress' => FALSE, 'stricton' => FALSE, 'failover' => array() ); 

Take a look at db_debug and set it to false.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.