-
Notifications
You must be signed in to change notification settings - Fork 1
/
database.php
84 lines (70 loc) · 1.63 KB
/
database.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
74
75
76
77
78
79
80
81
82
83
84
<?php
require 'local-config.php';
@session_start();
class database {
private $hostname;
private $username;
private $password;
private $database;
private $connect;
private $select_db;
public function __construct(){
$this->hostname = DB_HOSTNAME;
$this->username = DB_USERNAME;
$this->password = DB_PASSWORD;
$this->database = DB_DATABASE;
}
public function db()
{
$this->hostname = DB_HOSTNAME;
$this->username = DB_USERNAME;
$this->password = DB_PASSWORD;;
$this->database = DB_DATABASE;
}
public function open_connection()
{
try
{
$this->connect = mysql_connect($this->hostname,$this->username,$this->password);
$this->select_db = mysql_select_db($this->database);
return $this->connect;
}
catch(exception $e)
{
return $e;
}
}
public function close_connection()
{
try
{
mysql_close($this->connect);
}
catch(exception $e)
{
return $e;
}
}
public function query($sql)
{
$error=NULL;
try{
$query=addslashes($sql);
$this->open_connection();
$sql = mysql_query($sql);
$error=addslashes(mysql_error ());
$lst_id=mysql_insert_id();
}
catch (Exception $e){
$error=addslashes($e);
}
if($error!=NULL){
$q="INSERT INTO log VALUES(NULL,'".$_SESSION['id']."','".$_SESSION['rank']."','$query','$error',NOW())";
mysql_query($q);
return array($error,-1);
}
$this->close_connection();
return array($sql,$lst_id);
}
}
?>