-
Notifications
You must be signed in to change notification settings - Fork 85
/
Database.class.php
62 lines (62 loc) · 1.38 KB
/
Database.class.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
<?php
class Database
{
protected $link;
private $host, $username, $password, $database;
public function __construct($host=null, $user=null, $password=null, $database=null)
{
$this->host = $host;
$this->user = $user;
$this->password = $password;
$this->database = $database;
$this->__connect();
}
private function __connect()
{
$this->link = @mysql_connect($this->host,$this->user,$this->password);
@mysql_select_db($this->database,$this->link);
}
public function __sleep()
{
return array('host', 'user', 'password', 'database');
}
public function __wakeup()
{
$this->__connect();
}
public function connect($host,$user,$password)
{
return mysql_connect($host,$user,$password);
}
public function select($database)
{
return mysql_select_db($database);
}
public function query($query)
{
return mysql_query($query);
}
public function fetch($result,$type=null)
{
if(strtoupper($type) == 'ASSOC')
{
return mysql_fetch_array($result,MYSQL_ASSOC);
}
elseif(strtoupper($type) == 'NUM')
{
return mysql_fetch_array($result,MYSQL_NUM);
}
else
{
return mysql_fetch_array($result,MYSQL_BOTH);
}
}
public function error()
{
return mysql_errno();
}
public function close($link)
{
return mysql_close($link);
}
}