note 116849 added to mysqli.error

From: Date: Tue, 10 Mar 2015 13:39:12 +0000
Subject: note 116849 added to mysqli.error
Groups: php.notes 
Request: Send a blank email to php-notes+get-201908@lists.php.net to get a copy of this message
I had to set mysqli_report(MYSQLI_REPORT_ALL) at the begin of my script to be able to catch mysqli errors within the catch block of my php code. Initially, I used the below code to throw and subsequent catch mysqli exceptions <?php try { $mysqli = new mysqli('localhost','root','pwd','db'); if ($mysqli->connect_errno) throw new Exception($mysqli->connect_error); } catch (Exception $e) { echo $e->getMessage(); } I realized the exception was being thrown before the actual throw statement and hence the catch block was not being called. My current code looks like mysqli_report(MYSQLI_REPORT_ALL) ; try { $mysqli = new mysqli('localhost','root','pwd','db'); /* I don't need to throw the exception, it's being thrown automatically */ } catch (Exception $e) { echo $e->getMessage(); } This works fine and I'm able to trap all mysqli errors ---- Server IP: 72.52.91.14 Probable Submitter: 196.201.57.1 ---- Manual Page -- http://php.net/manual/en/mysqli.error.php Edit -- https://master.php.net/note/edit/116849 Del: integrated -- https://master.php.net/note/delete/116849/integrated Del: useless -- https://master.php.net/note/delete/116849/useless Del: bad code -- https://master.php.net/note/delete/116849/bad+code Del: spam -- https://master.php.net/note/delete/116849/spam Del: non-english -- https://master.php.net/note/delete/116849/non-english Del: in docs -- https://master.php.net/note/delete/116849/in+docs Del: other reasons-- https://master.php.net/note/delete/116849 Reject -- https://master.php.net/note/reject/116849 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#201908) next »