Revision 202, 2.3 KB
(checked in by exi, 15 years ago)
|
Fixed a bug belonging to the new mysql version code.
|
Line | |
---|
1 | <?php |
---|
2 | |
---|
3 | class DBConnection |
---|
4 | { |
---|
5 | function DBConnection() |
---|
6 | { |
---|
7 | static $conn_id; |
---|
8 | |
---|
9 | if (is_resource($conn_id)) |
---|
10 | { |
---|
11 | $this->id_ = $conn_id; |
---|
12 | return; |
---|
13 | } |
---|
14 | if (!$this->id_ = mysql_connect(DB_HOST, DB_USER, DB_PASS)) |
---|
15 | die("Unable to connect to mysql database."); |
---|
16 | |
---|
17 | mysql_select_db(DB_NAME); |
---|
18 | $conn_id = $this->id_; |
---|
19 | } |
---|
20 | |
---|
21 | function id() |
---|
22 | { |
---|
23 | return $this->id_; |
---|
24 | } |
---|
25 | |
---|
26 | function affectedRows() |
---|
27 | { |
---|
28 | return mysql_affected_rows($this->id_); |
---|
29 | } |
---|
30 | } |
---|
31 | |
---|
32 | class DBQuery |
---|
33 | { |
---|
34 | function DBQuery() |
---|
35 | { |
---|
36 | $this->executed_ = false; |
---|
37 | $this->dbconn_ = new DBConnection; |
---|
38 | } |
---|
39 | |
---|
40 | function execute($sql) |
---|
41 | { |
---|
42 | $t1 = strtok(microtime(), ' ') + strtok(''); |
---|
43 | |
---|
44 | $this->resid_ = mysql_query($sql, $this->dbconn_->id()); |
---|
45 | |
---|
46 | if ($this->resid_ == false) |
---|
47 | { |
---|
48 | if (defined('DB_HALTONERROR') && DB_HALTONERROR) |
---|
49 | { |
---|
50 | echo "Database error: " . mysql_error($this->dbconn_->id()) . "<br>"; |
---|
51 | echo "SQL: " . $sql . "<br>"; |
---|
52 | exit; |
---|
53 | } |
---|
54 | else |
---|
55 | { |
---|
56 | return false; |
---|
57 | } |
---|
58 | } |
---|
59 | |
---|
60 | $this->exectime_ = strtok(microtime(), ' ') + strtok('') - $t1; |
---|
61 | $this->executed_ = true; |
---|
62 | |
---|
63 | if (KB_PROFILE == 2) |
---|
64 | { |
---|
65 | file_put_contents('/tmp/profile.lst', $sql . "\nExecution time: " . $this->exectime_ . "\n", FILE_APPEND); |
---|
66 | } |
---|
67 | |
---|
68 | return true; |
---|
69 | } |
---|
70 | |
---|
71 | function recordCount() |
---|
72 | { |
---|
73 | return mysql_num_rows($this->resid_); |
---|
74 | } |
---|
75 | |
---|
76 | function getRow() |
---|
77 | { |
---|
78 | if ($this->resid_) |
---|
79 | { |
---|
80 | return mysql_fetch_assoc($this->resid_); |
---|
81 | } |
---|
82 | return false; |
---|
83 | } |
---|
84 | |
---|
85 | function rewind() |
---|
86 | { |
---|
87 | @mysql_data_seek($this->resid_, 0); |
---|
88 | } |
---|
89 | |
---|
90 | function getInsertID() |
---|
91 | { |
---|
92 | return mysql_insert_id(); |
---|
93 | } |
---|
94 | |
---|
95 | function execTime() |
---|
96 | { |
---|
97 | return $this->exectime_; |
---|
98 | } |
---|
99 | |
---|
100 | function executed() |
---|
101 | { |
---|
102 | return $this->executed_; |
---|
103 | } |
---|
104 | |
---|
105 | function getErrorMsg() |
---|
106 | { |
---|
107 | $msg = $this->sql_ . "<br>"; |
---|
108 | $msg .= "Query failed. " . mysql_error($this->dbconn_->id()); |
---|
109 | |
---|
110 | return $msg; |
---|
111 | } |
---|
112 | } |
---|
113 | ?> |
---|