1 | <?php |
---|
2 | class mysql |
---|
3 | { |
---|
4 | var $handle; |
---|
5 | var $host; |
---|
6 | var $user; |
---|
7 | var $password; |
---|
8 | var $database; |
---|
9 | var $rid; |
---|
10 | var $cur_row; |
---|
11 | var $used_time; |
---|
12 | |
---|
13 | // constructor, diese funktion wird aufgerufen beim instantieren eines neuen objekts |
---|
14 | function mysql ($host = "localhost", $user = "root", $pass = "", $database = "vng") |
---|
15 | { |
---|
16 | if ($host) |
---|
17 | { |
---|
18 | $this->connect($host, $user, $pass, $database); |
---|
19 | } |
---|
20 | } |
---|
21 | |
---|
22 | function connect ($host = "localhost", $user = "root", $pass = "", $database = "vng") |
---|
23 | { |
---|
24 | if ($host) |
---|
25 | { |
---|
26 | $this->setup($host, $user, $pass, $database); |
---|
27 | } |
---|
28 | |
---|
29 | $this->handle = mysql_connect($this->host, $this->user, $this->password, $this->database); |
---|
30 | |
---|
31 | if (!is_resource($this->handle)) |
---|
32 | { |
---|
33 | $this->error("connection to '".$this->host."' failed."); |
---|
34 | } |
---|
35 | |
---|
36 | if (!mysql_select_db($this->database, $this->handle)) |
---|
37 | { |
---|
38 | $this->error("selecting database '".$this->database."' failed."); |
---|
39 | } |
---|
40 | } |
---|
41 | |
---|
42 | function setup ($host, $user, $pass, $db) |
---|
43 | { |
---|
44 | $this->host = $host; |
---|
45 | $this->user = $user; |
---|
46 | $this->password = $pass; |
---|
47 | $this->database = $db; |
---|
48 | } |
---|
49 | |
---|
50 | function query ($query) |
---|
51 | { |
---|
52 | $result = mysql_query($query, $this->handle); |
---|
53 | if ($result != true) |
---|
54 | { |
---|
55 | $this->error("executing statement '".$query."' failed."); |
---|
56 | return false; |
---|
57 | } |
---|
58 | |
---|
59 | $this->cur_row = 0; |
---|
60 | $this->rid = $result; |
---|
61 | return $result; |
---|
62 | } |
---|
63 | |
---|
64 | function fetch_array ($rid = null, $max_rows = 0) |
---|
65 | { |
---|
66 | if ($rid == null) |
---|
67 | { |
---|
68 | $rid = $this->rid; |
---|
69 | } |
---|
70 | if (!is_resource($rid)) |
---|
71 | { |
---|
72 | $this->error("invalid resource id supplied to fetch_array()"); |
---|
73 | return false; |
---|
74 | } |
---|
75 | $tmp = mysql_fetch_assoc($rid); |
---|
76 | if (!$tmp) |
---|
77 | { |
---|
78 | return false; |
---|
79 | } |
---|
80 | $this->cur_row++; |
---|
81 | |
---|
82 | if ($max_rows) |
---|
83 | { |
---|
84 | if ($this->cur_row > $max_rows) |
---|
85 | { |
---|
86 | // limit exceeded |
---|
87 | return false; |
---|
88 | } |
---|
89 | } |
---|
90 | |
---|
91 | return $tmp; |
---|
92 | } |
---|
93 | |
---|
94 | function num_rows($rid = null) |
---|
95 | { |
---|
96 | if ($rid == null) |
---|
97 | { |
---|
98 | $rid = $this->rid; |
---|
99 | } |
---|
100 | if (!is_resource($rid)) |
---|
101 | { |
---|
102 | $this->error("invalid resource id supplied to num_rows()"); |
---|
103 | return false; |
---|
104 | } |
---|
105 | return mysql_num_rows($rid); |
---|
106 | } |
---|
107 | |
---|
108 | function _gethandle () |
---|
109 | { |
---|
110 | return $this->handle; |
---|
111 | } |
---|
112 | |
---|
113 | function error ($text) |
---|
114 | { |
---|
115 | echo "<br><b>mysql::error:</b> <i>$text</i>\n"; |
---|
116 | # echo "<br><b>ads::debug:</b> <i>".ads_error().ads_errormsg()."</i>\n"; |
---|
117 | } |
---|
118 | } |
---|
119 | ?> |
---|