1 <?php |
|
2 /*********************************************************************** |
|
3 |
|
4 Copyright (C) 2002-2005 Dan Fuhry (dan@enanocms.org) |
|
5 |
|
6 This file is part of the PunBB to Enano compatibility layer. No part |
|
7 of this file is included with any official PunBB distribution. |
|
8 |
|
9 PunBB is free software; you can redistribute it and/or modify it |
|
10 under the terms of the GNU General Public License as published |
|
11 by the Free Software Foundation; either version 2 of the License, |
|
12 or (at your option) any later version. |
|
13 |
|
14 PunBB is distributed in the hope that it will be useful, but |
|
15 WITHOUT ANY WARRANTY; without even the implied warranty of |
|
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
17 GNU General Public License for more details. |
|
18 |
|
19 You should have received a copy of the GNU General Public License |
|
20 along with this program; if not, write to the Free Software |
|
21 Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
|
22 MA 02111-1307 USA |
|
23 |
|
24 ************************************************************************/ |
|
25 |
|
26 /** |
|
27 * A compatibility layer to allow PunBB to use Enano's database abstraction layer. |
|
28 * @package Punano |
|
29 * @subpackage Database compatibility layer |
|
30 * @copyright (C) 2007 Dan Fuhry |
|
31 * @license GNU General Public License |
|
32 */ |
|
33 |
|
34 class PunBB_DBAL_Enano |
|
35 { |
|
36 |
|
37 var $prefix; |
|
38 var $link_id; |
|
39 var $query_result; |
|
40 |
|
41 var $saved_queries = array(); |
|
42 var $num_queries = 0; |
|
43 |
|
44 |
|
45 function PunBB_DBAL_Enano($db_host, $db_username, $db_password, $db_name, $db_prefix, $p_connect) |
|
46 { |
|
47 $this->prefix = table_prefix . 'pun_'; |
|
48 } |
|
49 |
|
50 function start_transaction() |
|
51 { |
|
52 return; |
|
53 } |
|
54 |
|
55 function end_transaction() |
|
56 { |
|
57 return; |
|
58 } |
|
59 |
|
60 function query($sql, $unbuffered = false) |
|
61 { |
|
62 global $db; |
|
63 if (defined('PUN_SHOW_QUERIES')) |
|
64 $q_start = pun_microtime(); |
|
65 |
|
66 if ($unbuffered) |
|
67 $this->query_result = $db->sql_unbuffered_query($sql); |
|
68 else |
|
69 $this->query_result = $db->sql_query($sql); |
|
70 |
|
71 if ($this->query_result) |
|
72 { |
|
73 if (defined('PUN_SHOW_QUERIES')) |
|
74 $this->saved_queries[] = array($sql, sprintf('%.5f', pun_microtime() - $q_start)); |
|
75 |
|
76 ++$this->num_queries; |
|
77 |
|
78 return $this->query_result; |
|
79 } |
|
80 else |
|
81 { |
|
82 if (defined('PUN_SHOW_QUERIES')) |
|
83 $this->saved_queries[] = array($sql, 0); |
|
84 |
|
85 return false; |
|
86 } |
|
87 } |
|
88 |
|
89 function result($query_id = 0, $row = 0) |
|
90 { |
|
91 return ($query_id) ? @mysql_result($query_id, $row) : false; |
|
92 } |
|
93 |
|
94 function fetch_assoc($query_id = 0) |
|
95 { |
|
96 global $db; |
|
97 return ($query_id) ? $db->fetchrow($query_id) : false; |
|
98 } |
|
99 |
|
100 function fetch_row($query_id = 0) |
|
101 { |
|
102 global $db; |
|
103 return ($query_id) ? $db->fetchrow_num($query_id) : false; |
|
104 } |
|
105 |
|
106 |
|
107 function num_rows($query_id = 0) |
|
108 { |
|
109 global $db; |
|
110 return ($query_id) ? @mysql_num_rows($query_id) : false; |
|
111 } |
|
112 |
|
113 function affected_rows() |
|
114 { |
|
115 global $db; |
|
116 return ($db->_conn) ? @mysql_affected_rows($db->_conn) : false; |
|
117 } |
|
118 |
|
119 function insert_id() |
|
120 { |
|
121 global $db; |
|
122 $ret = ($db->_conn) ? @mysql_insert_id($db->_conn) : false; |
|
123 return $ret; |
|
124 } |
|
125 |
|
126 function get_num_queries() |
|
127 { |
|
128 return $this->num_queries; |
|
129 } |
|
130 |
|
131 function get_saved_queries() |
|
132 { |
|
133 return $this->saved_queries; |
|
134 } |
|
135 |
|
136 function free_result($query_id = false) |
|
137 { |
|
138 global $db; |
|
139 return ($query_id) ? $db->free_result($query_id) : false; |
|
140 } |
|
141 |
|
142 function escape($str) |
|
143 { |
|
144 global $db; |
|
145 if (is_array($str)) |
|
146 return ''; |
|
147 else if (function_exists('mysql_real_escape_string')) |
|
148 return $db->escape($str); |
|
149 else |
|
150 return mysql_escape_string($str); |
|
151 } |
|
152 |
|
153 |
|
154 function error() |
|
155 { |
|
156 $result['error_sql'] = @current(@end($this->saved_queries)); |
|
157 $result['error_no'] = @mysql_errno($this->link_id); |
|
158 $result['error_msg'] = @mysql_error($this->link_id); |
|
159 |
|
160 return $result; |
|
161 } |
|
162 |
|
163 |
|
164 function close() |
|
165 { |
|
166 return false; |
|
167 } |
|
168 |
|
169 } |
|
170 |
|