Mysql error handling/Try catch

2019-09-15 01:52发布

问题:

If table column does not exist mysql shows error .How to fix it using try catch or error handling method

Thanks

回答1:

you can handle the mysql error in this way

 if ( ! $this->db->query('SELECT `name`,`age` FROM `example`'))
{
        $error = $this->db->error(); // Has keys 'code' and 'message'
}