2 /***************************************************************************
5 * begin : Saturday, Feb 13, 2001
6 * copyright : (C) 2001 The phpBB Group
7 * email : support@phpbb.com
9 * $Id: mysql.php,v 1.16 2002/03/19 01:07:36 psotfx Exp $
11 ***************************************************************************/
13 /***************************************************************************
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 2 of the License, or
18 * (at your option) any later version.
20 ***************************************************************************/
22 if(!defined("SQL_LAYER"))
25 define("SQL_LAYER","mysql");
33 var $rowset = array();
39 function sql_db($sqlserver, $sqluser, $sqlpassword, $database, $persistency = true)
42 $this->persistency = $persistency;
43 $this->user = $sqluser;
44 $this->password = $sqlpassword;
45 $this->server = $sqlserver;
46 $this->dbname = $database;
48 if($this->persistency)
50 $this->db_connect_id = @mysql_pconnect($this->server, $this->user, $this->password);
54 $this->db_connect_id = @mysql_connect($this->server, $this->user, $this->password);
56 if($this->db_connect_id)
60 $this->dbname = $database;
61 $dbselect = @mysql_select_db($this->dbname);
64 @mysql_close($this->db_connect_id);
65 $this->db_connect_id = $dbselect;
68 return $this->db_connect_id;
81 if($this->db_connect_id)
83 if($this->query_result)
85 @mysql_free_result($this->query_result);
87 $result = @mysql_close($this->db_connect_id);
99 function sql_query($query = "", $transaction = FALSE)
101 // Remove any pre-existing queries
102 unset($this->query_result);
105 $this->num_queries++;
107 $this->query_result = @mysql_query($query, $this->db_connect_id);
109 if($this->query_result)
111 unset($this->row[$this->query_result]);
112 unset($this->rowset[$this->query_result]);
113 return $this->query_result;
117 return ( $transaction == END_TRANSACTION ) ? true : false;
122 // Other query methods
124 function sql_numrows($query_id = 0)
128 $query_id = $this->query_result;
132 $result = @mysql_num_rows($query_id);
140 function sql_affectedrows()
142 if($this->db_connect_id)
144 $result = @mysql_affected_rows($this->db_connect_id);
152 function sql_numfields($query_id = 0)
156 $query_id = $this->query_result;
160 $result = @mysql_num_fields($query_id);
168 function sql_fieldname($offset, $query_id = 0)
172 $query_id = $this->query_result;
176 $result = @mysql_field_name($query_id, $offset);
184 function sql_fieldtype($offset, $query_id = 0)
188 $query_id = $this->query_result;
192 $result = @mysql_field_type($query_id, $offset);
200 function sql_fetchrow($query_id = 0)
204 $query_id = $this->query_result;
208 $this->row[$query_id] = @mysql_fetch_array($query_id);
209 return $this->row[$query_id];
216 function sql_fetchrowset($query_id = 0)
220 $query_id = $this->query_result;
224 unset($this->rowset[$query_id]);
225 unset($this->row[$query_id]);
226 while($this->rowset[$query_id] = @mysql_fetch_array($query_id))
228 $result[] = $this->rowset[$query_id];
237 function sql_fetchfield($field, $rownum = -1, $query_id = 0)
241 $query_id = $this->query_result;
247 $result = @mysql_result($query_id, $rownum, $field);
251 if(empty($this->row[$query_id]) && empty($this->rowset[$query_id]))
253 if($this->sql_fetchrow())
255 $result = $this->row[$query_id][$field];
260 if($this->rowset[$query_id])
262 $result = $this->rowset[$query_id][$field];
264 else if($this->row[$query_id])
266 $result = $this->row[$query_id][$field];
277 function sql_rowseek($rownum, $query_id = 0){
280 $query_id = $this->query_result;
284 $result = @mysql_data_seek($query_id, $rownum);
292 function sql_nextid(){
293 if($this->db_connect_id)
295 $result = @mysql_insert_id($this->db_connect_id);
303 function sql_freeresult($query_id = 0){
306 $query_id = $this->query_result;
311 unset($this->row[$query_id]);
312 unset($this->rowset[$query_id]);
314 @mysql_free_result($query_id);
323 function sql_error($query_id = 0)
325 $result["message"] = @mysql_error($this->db_connect_id);
326 $result["code"] = @mysql_errno($this->db_connect_id);