i have
<?php error_reporting(e_all); ini_set('display_errors', 1); require_once "configuration.php"; header('content-type: application/json'); try { $mysqli = new mysqli(mysql_server, mysql_username, mysql_password, mysql_database); $mysqli->set_charset("utf8"); } catch (exception $e) { echo json_encode( array( 'msg' => $e->getmessage() ) ); }
and if mysqli
not enabled not catch error:
fatal error: uncaught error: class 'mysqli' not found in c:\test\db_connect.php:8
stack trace:
#0 c:\test\getcontacts.php(2): require_once()
#1 {main} thrown in c:\test\db_connect.php on line 8
what can catches error?
i have tried 1 didn't work:
<?php error_reporting(e_all); ini_set('display_errors', 1); require_once "configuration.php"; header('content-type: application/json'); try { if(!extension_loaded('mysqli')) { throw new exception('mysqli not enabled'); } $mysqli = new mysqli(mysql_server, mysql_username, mysql_password, mysql_database); $mysqli->set_charset("utf8"); } catch (exception $e) { echo json_encode( array( 'msg' => $e->getmessage() ) ); }
this 1 not halt, continues execute script.
{"msg":"mysqli not enabled"}
notice: undefined variable: mysqli in c:\test\getcontacts.php on line 99
fatal error: uncaught error: call member function query() on null in c:\test\getcontacts.php:99 stack trace: #0 {main} thrown in c:\test\getcontacts.php on line 99
it's odd wouldn't installed if you're rolling own guess omitted. check see if procedural functions exist
if(!function_exists('mysqli_connect')) { throw new exception('mysqli not enabled'); }
Comments
Post a Comment