-
Notifications
You must be signed in to change notification settings - Fork 0
/
_db_mysql.php
73 lines (63 loc) · 1.91 KB
/
_db_mysql.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?php
ini_set('display_error', 'On');
global $dbh;
$dbh = connect();
function connect()
{
// MySQL Hostname / Server (for eg: 'localhost')
$sql_host = 'localhost';
$sql_port = '3306';
// MySQL Database Name
$sql_name = 'core';
// MySQL Database User
$sql_user = 'root';
// MySQL Database Password
$sql_pass = '';
$dbConnect = mysqli_connect($sql_host, $sql_user, $sql_pass, $sql_name, $sql_port);
mysqli_set_charset($dbConnect, 'utf8');
return $dbConnect;
}
function retrieve($sql)
{
$dbConnect = connect();
if ($dbh === null) {
return;
}
$result = mysqli_query($dbConnect, $sql);
if ($result !== false) {
$sql_numrows = mysqli_num_rows($sql);
if ($sql_numrows > 0) {
while ($sql_fetch = mysqli_fetch_assoc($sql_query)) {
$get[] = $sql_fetch;
}
return $get;
}
} else {
$error = 'ไม่สามารถติดต่อกับฐานข้อมูลได้';
echo $error;
//pg_close($dbh);
return;
}
}
function retrieve_params($sql, $arr)
{
global $error;
$dbh = connect();
if ($dbh === null) {
return;
}
$result = pg_query_params($dbh, $sql, $arr);
if ($result !== false) {
$rows = [];
while ($row = pg_fetch_assoc($result)) {
$rows[] = $row;
}
pg_free_result($result);
pg_close($dbh);
return $rows;
} else {
$error = 'ไม่สามารถติดต่อกับฐานข้อมูลได้';
pg_close($dbh);
return;
}
}