blob: 618a7e6b6a684fc9d0192ba8dc48ad2888843966 (
plain)
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
<?
function db()
{
return Database::getSocket();
}
class Database
{
private static $socket = null;
private function __construct() {}
public static function getSocket()
{
if (self::$socket === null)
self::$socket = new DatabaseSocket(RR_DB_USER, RR_DB_PASS, RR_DB_HOST, RR_DB_PORT);
return self::$socket;
}
}
class DatabaseSocket
{
private $link;
public function __construct($user, $pass = null, $host = 'localhost')
{
$this->link = mysql_connect($host, $user, $pass);
}
public function safe($text)
{
return mysql_real_escape_string($text, $this->link);
}
public function error()
{
return mysql_error($this->link);
}
public function query($sql)
{
return mysql_query($sql, $this->link);
}
public function insert($sql)
{
$this->query($sql);
return mysql_insert_id($this->link);
}
public function execute($sql)
{
$this->query($sql);
return mysql_affected_rows($this->link);
}
public function ping()
{
mysql_ping($this->link);
}
public function getArray($sql)
{
$rs = $this->query($sql);
while ($row = mysql_fetch_assoc($rs))
$data[] = $row;
return $data;
}
public function getRow($sql)
{
$rs = $this->query($sql);
return mysql_fetch_assoc($rs);
}
public function getValue($sql)
{
$rs = $this->query($sql);
$row = mysql_fetch_row($rs);
return $row[0];
}
public function getLink()
{
return $this->link;
}
public function selectDb($database)
{
mysql_select_db($database, $this->link);
}
}
?>
|