2 /***************************************************************************
5 * begin : Saturday, Feb 13, 2001
6 * copyright : (C) 2001 The phpBB Group
7 * email : supportphpbb.com
9 * $Id: mysql4.php,v 1.5.2.1 2005/09/18 16:17:20 acydburn 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","mysql4");
33 var $rowset = array();
35 var $in_transaction = 0;
40 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 $this->db_connect_id = ($this->persistency) ? mysql_pconnect($this->server, $this->user, $this->password) : mysql_connect($this->server, $this->user, $this->password);
50 if( $this->db_connect_id )
54 $this->dbname = $database;
55 $dbselect = mysql_select_db($this->dbname);
59 mysql_close($this->db_connect_id);
60 $this->db_connect_id = $dbselect;
64 return $this->db_connect_id;
77 if( $this->db_connect_id )
80 // Commit any remaining transactions
82 if( $this->in_transaction )
84 mysql_query("COMMIT", $this->db_connect_id);
87 return mysql_close($this->db_connect_id);
98 function sql_query($query = "", $transaction = FALSE)
101 // Remove any pre-existing queries
103 unset($this->query_result);
107 $this->num_queries++;
108 if( $transaction == BEGIN_TRANSACTION && !$this->in_transaction )
110 $result = mysql_query("BEGIN", $this->db_connect_id);
115 $this->in_transaction = TRUE;
118 $this->query_result = mysql_query($query, $this->db_connect_id);
122 if( $transaction == END_TRANSACTION && $this->in_transaction )
124 $result = mysql_query("COMMIT", $this->db_connect_id);
128 if( $this->query_result )
130 unset($this->row[$this->query_result]);
131 unset($this->rowset[$this->query_result]);
133 if( $transaction == END_TRANSACTION && $this->in_transaction )
135 $this->in_transaction = FALSE;
137 if ( !mysql_query("COMMIT", $this->db_connect_id) )
139 mysql_query("ROLLBACK", $this->db_connect_id);
144 return $this->query_result;
148 if( $this->in_transaction )
150 mysql_query("ROLLBACK", $this->db_connect_id);
151 $this->in_transaction = FALSE;
158 // Other query methods
160 function sql_numrows($query_id = 0)
164 $query_id = $this->query_result;
167 return ( $query_id ) ? mysql_num_rows($query_id) : false;
170 function sql_affectedrows()
172 return ( $this->db_connect_id ) ? mysql_affected_rows($this->db_connect_id) : false;
175 function sql_numfields($query_id = 0)
179 $query_id = $this->query_result;
182 return ( $query_id ) ? mysql_num_fields($query_id) : false;
185 function sql_fieldname($offset, $query_id = 0)
189 $query_id = $this->query_result;
192 return ( $query_id ) ? mysql_field_name($query_id, $offset) : false;
195 function sql_fieldtype($offset, $query_id = 0)
199 $query_id = $this->query_result;
202 return ( $query_id ) ? mysql_field_type($query_id, $offset) : false;
205 function sql_fetchrow($query_id = 0)
209 $query_id = $this->query_result;
214 $this->row[$query_id] = mysql_fetch_array($query_id, MYSQL_ASSOC);
215 return $this->row[$query_id];
223 function sql_fetchrowset($query_id = 0)
227 $query_id = $this->query_result;
232 unset($this->rowset[$query_id]);
233 unset($this->row[$query_id]);
235 while($this->rowset[$query_id] = mysql_fetch_array($query_id, MYSQL_ASSOC))
237 $result[] = $this->rowset[$query_id];
248 function sql_fetchfield($field, $rownum = -1, $query_id = 0)
252 $query_id = $this->query_result;
259 $result = mysql_result($query_id, $rownum, $field);
263 if( empty($this->row[$query_id]) && empty($this->rowset[$query_id]) )
265 if( $this->sql_fetchrow() )
267 $result = $this->row[$query_id][$field];
272 if( $this->rowset[$query_id] )
274 $result = $this->rowset[$query_id][0][$field];
276 else if( $this->row[$query_id] )
278 $result = $this->row[$query_id][$field];
291 function sql_rowseek($rownum, $query_id = 0)
295 $query_id = $this->query_result;
298 return ( $query_id ) ? mysql_data_seek($query_id, $rownum) : false;
301 function sql_nextid()
303 return ( $this->db_connect_id ) ? mysql_insert_id($this->db_connect_id) : false;
306 function sql_freeresult($query_id = 0)
310 $query_id = $this->query_result;
315 unset($this->row[$query_id]);
316 unset($this->rowset[$query_id]);
318 mysql_free_result($query_id);
330 $result['message'] = mysql_error($this->db_connect_id);
331 $result['code'] = mysql_errno($this->db_connect_id);