1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
| equire __DIR__ . '/vendor/autoload.php';
use Firebase\JWT\JWT;
use Firebase\JWT\Key;
class DB {
private static $db = null;
/**
* Get the instanciated MySQLi connection.
* @return object The MySQLi object
*/
private static function _getDb() {
if ( self::$db === null ) {
set_error_handler( function( $errno, $errstr, $errfile, $errline, array $errcontext = [] ) {
// error was suppressed with the @-operator
if ( 0 === error_reporting() ) {
return false;
}
throw new ErrorException( $errstr, 0, $errno, $errfile, $errline );
});
try {
self::$db = new mysqli( DB_HOST, DB_USER, DB_PASS, DB_NAME, DB_PORT );
self::$db->set_charset( "utf8" );
} catch ( ErrorException $e ) {
throw new Exception( $e->getMessage(), 500 );
}
restore_error_handler();
}
return self::$db;
} |
Partager