|
@@ -1,27 +1,46 @@
|
1
|
1
|
<?php
|
2
|
|
-require_once "misc/config.php";
|
3
|
2
|
require_once "utils.php";
|
|
3
|
+require_once "misc/config.php";
|
4
|
4
|
|
5
|
|
-function get_database()
|
|
5
|
+function database_get()
|
6
|
6
|
{
|
7
|
7
|
static $init = 0;
|
8
|
8
|
static $database = NULL;
|
9
|
9
|
if ($init == 0)
|
10
|
10
|
{
|
11
|
11
|
$init = 1;
|
|
12
|
+ global $database_host;
|
|
13
|
+ global $database_port;
|
|
14
|
+ global $database_name;
|
|
15
|
+ global $database_user;
|
|
16
|
+ global $database_pass;
|
12
|
17
|
try
|
13
|
18
|
{
|
14
|
|
- $database = new PDO("mysql:host:$database_host;$database_port;".
|
|
19
|
+ $database = new PDO("mysql:host=$database_host;port=$database_port;".
|
15
|
20
|
"dbname=$database_name", $database_user,
|
16
|
21
|
$database_pass);
|
17
|
22
|
}
|
18
|
23
|
catch (Exception $e)
|
19
|
24
|
{
|
20
|
|
- var_dump($e);
|
21
|
|
- error(500, "Database Fail");
|
|
25
|
+ error(500, "Database Fail Connect");
|
22
|
26
|
}
|
23
|
27
|
}
|
24
|
28
|
return $database;
|
25
|
29
|
}
|
26
|
30
|
|
|
31
|
+function database_exec($query, $args)
|
|
32
|
+{
|
|
33
|
+ $q = database_get()->prepare($query);
|
|
34
|
+ if (!$q->execute($args))
|
|
35
|
+ error(500, "Database Fail Query");
|
|
36
|
+ return $q;
|
|
37
|
+}
|
|
38
|
+
|
|
39
|
+function database_query($query)
|
|
40
|
+{
|
|
41
|
+ $q = database_get()->query($query);
|
|
42
|
+ if (!$q)
|
|
43
|
+ error(500, "Database Fail Query");
|
|
44
|
+ return $q;
|
|
45
|
+}
|
27
|
46
|
?>
|