-
Notifications
You must be signed in to change notification settings - Fork 1
/
db.php
66 lines (50 loc) · 1.29 KB
/
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
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
<?php
class Sanuich_db {
private $dbcnx;
function __construct()
{
$db = include('app'.DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'database.php');
$dbcnx = mysqli_connect(
$db['default']['connection']['hostname'],
$db['default']['connection']['username'],
$db['default']['connection']['password'],
$db['default']['connection']['database']
) or exit('error server');
mysqli_select_db(
$dbcnx,
$db['default']['connection']['database']
) or exit('error DB');
mysqli_set_charset($dbcnx, 'utf8');
$this->dbcnx = $dbcnx;
}
function get_array($query){
$result = mysqli_query($this->dbcnx, $query) or exit('error operation '.$query);
$row=array();
$num_results = mysqli_num_rows($result) ;
for ($i=0; $i <$num_results; $i++)
$row[$i] = mysqli_fetch_array($result);
return $row;
}
function insert($query)
{
$rez = mysqli_query($this->dbcnx, $query);
if($rez!=false)
{
$newid = mysqli_insert_id($this->dbcnx);
return $newid;
}
else exit('error operation '.$query);
}
function __destruct(){
mysqli_close($this->dbcnx);}
}
function get_array($query){
global $san_db;
return $san_db->get_array($query);
}
function insert($query){
global $san_db;
return $san_db->insert($query);
}
global $san_db;
$san_db = new Sanuich_db;