-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.php
46 lines (37 loc) · 1.3 KB
/
init.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php
// This will let to have different config.php files on different servers
if (!file_exists('config.php')) {
trigger_error('Create config.php based on config.sample.php');
}
$config = require 'config.php';
// Should be always E_ALL
error_reporting(E_ALL);
// whether to display errors or not
ini_set('display_errors', $config['dev_mode']);
session_start();
/**** Backward compatibility block allowing this example to work on PHP 8.0+ ****/
$mysqli_class_name = 'mysqli';
if (version_compare(PHP_VERSION, '8.2', '<')) {
function mysqli_execute_query(mysqli $mysqli, string $query, ?array $params = null)
{
$stmt = $mysqli->prepare($query);
if ($params) {
$types = str_repeat("s", count($params));
$stmt->bind_param($types, ...$params);
}
$stmt->execute();
return $stmt->get_result();
}
class my_mysqli extends mysqli {
public function execute_query(string $query, ?array $params = null)
{
return mysqli_execute_query($this, $query, $params);
}
}
$mysqli_class_name = 'my_mysqli';
}
// turn on error reporting for mysql
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
// connect to mysql
$db = new $mysqli_class_name(...$config['db']);
$db->set_charset($config['db_charset']);