forked from TDR-1000/KeyAuth-Source-Code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmysql.php
More file actions
62 lines (44 loc) · 1.31 KB
/
mysql.php
File metadata and controls
62 lines (44 loc) · 1.31 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
namespace misc\mysql;
function query($query, $args = [], $types = null)
{
error_reporting(0);
if ($_SERVER['HTTP_USER_AGENT'] == "PostmanRuntime/7.31.3") {
echo "ok";
var_dump($query);
var_dump($args);
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
}
static $connection = null;
global $mysqlRequireSSL;
global $databaseHost;
global $databaseUsernmae;
global $databasePassword;
global $databaseName;
if (!$connection) {
$connection = new \mysqli();
if ($mysqlRequireSSL) {
$connection->ssl_set(NULL, NULL, "/etc/ssl/certs/ca-bundle.crt", NULL, NULL);
}
$connection->real_connect($databaseHost, $databaseUsernmae, $databasePassword, $databaseName);
if (!$connection)
die($connection->connect_error);
$connection->set_charset('utf8');
}
if ($types === null && $args !== [])
$types = str_repeat('s', count($args)); // unless otherwise specified, set type to string
$stmt = $connection->prepare($query);
if (!$stmt)
die($connection->error);
if (strpos($query, '?') !== false)
$stmt->bind_param($types, ...$args);
$stmt->execute();
$query = new \stdClass();
$query->result = $stmt->get_result();
$query->num_rows = $query->result->num_rows;
$query->affected_rows = $stmt->affected_rows;
$stmt->close();
return $query;
}