Welcome Guest, Not a member yet? Register   Sign In
Catch database exception
#4

(This post was last modified: 10-15-2020, 12:11 AM by InsiteFX.)

I was surfing the web and came across this maybe it will help you out.

Code:
How to use try catch with MySQL
The PHP libraries for MySQL, PDO, and mysqli, have different modes for error handling.
If you do not have exceptions enables for those libraries, you can’t use try catch blocks.
This makes error handling different and perhaps more complicated.

PDO
In PDO, you must enable ERRMODE_EXCEPTION when creating the connection.

// connect to MySQL
$conn = new PDO('mysql:host=localhost;dbname=stackifydb;charset=utf8mb4', 'username', 'password');

//PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

Learn more about PDO attributes from the PHP docs.

MySQL
For mysqli, you must do something similar:

mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);

Learn more from the MySQL docs.

This may help others out also.

After looking at the MySQLi connection it is not setting these up in CodeIgniter.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply


Messages In This Thread
Catch database exception - by Michal_PB1 - 10-13-2020, 11:44 AM
RE: Catch database exception - by InsiteFX - 10-13-2020, 02:46 PM
RE: Catch database exception - by Michal_PB1 - 10-14-2020, 07:25 AM
RE: Catch database exception - by InsiteFX - 10-14-2020, 11:33 PM
RE: Catch database exception - by Michal_PB1 - 11-30-2020, 01:13 PM
RE: Catch database exception - by InsiteFX - 11-30-2020, 03:07 PM
RE: Catch database exception - by Michal_PB1 - 11-30-2020, 03:19 PM



Theme © iAndrew 2016 - Forum software by © MyBB