-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb.php
30 lines (27 loc) · 837 Bytes
/
db.php
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
<?php
require_once dirname(__FILE__) . "/modules/HttpException/HttpException.php";
require_once dirname(__FILE__) . "/config/database.php"; # import database settings
final class proxy_mysqli extends mysqli {
public function query($db_query, $resultmode = MYSQLI_STORE_RESULT, $msg = '') {
$db_result = parent::query($db_query, $resultmode);
if ($db_result === FALSE) {
throw new HttpException(500, ($msg ? $msg . ': ' : '') . $this->error);
}
return $db_result;
}
}
function db_ensure_connection()
{
static $connection = false;
if (!$connection)
{
$connection = new proxy_mysqli(DB_SERVER, DB_USERNAME, DB_PASSWORD, DB_NAME);
if ($connection->connect_error || mysqli_connect_error() || $connection->error)
{
throw new HttpException(500);
}
$connection->set_charset('latin1');
}
return $connection;
}
?>