Fix checkRpItemsPosition
[ryzomcore.git] / web / public_php / admin / functions_mysqli.php
blob82ef9efa73fc83b8c78f504f8e82c8480ca00fd0
1 <?php
2 /***************************************************************************
3 * mysql.php
4 * -------------------
5 * begin : Saturday, Feb 13, 2001
6 * copyright : (C) 2001 The phpBB Group
7 * email : support@phpbb.com
9 * $Id: functions_mysql.php,v 1.2 2006/07/06 15:17:22 powles 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 /***************************************************************************
24 * NOTE: this is striped down version from phpBB mysql.php file
25 * modified to work with mysqli
27 ***************************************************************************/
29 if(!defined("SQL_LAYER"))
32 define("SQL_LAYER","mysqli");
34 class sql_db
37 var $db_connect_id;
38 var $query_result;
39 var $num_queries = 0;
42 // Constructor
44 function __construct($sqlserver, $sqluser, $sqlpassword, $database, $persistency = true)
47 $this->persistency = $persistency;
48 $this->user = $sqluser;
49 $this->password = $sqlpassword;
50 $this->server = $sqlserver;
51 $this->dbname = $database;
53 if($this->persistency)
55 $this->server = 'p:'.$this->server;
58 $this->db_connect_id = mysqli_connect($this->server, $this->user, $this->password);
59 if($this->db_connect_id)
61 if($database != "")
63 $this->dbname = $database;
64 $dbselect = mysqli_select_db($this->db_connect_id, $this->dbname);
65 if(!$dbselect)
67 mysqli_close($this->db_connect_id);
68 $this->db_connect_id = $dbselect;
71 return $this->db_connect_id;
73 else
75 throw new \RuntimeException('Connection to mySQL failed!');
80 // Other base methods
82 function sql_close()
84 if($this->db_connect_id)
86 if($this->query_result)
88 @mysqli_free_result($this->query_result);
90 $result = mysqli_close($this->db_connect_id);
91 return $result;
93 else
95 return false;
100 // Base query method
102 function sql_query($query = "", $transaction = FALSE)
104 // Remove any pre-existing queries
105 unset($this->query_result);
106 if($query != "")
108 nt_common_add_debug($query);
109 $this->num_queries++;
110 $this->query_result = mysqli_query($this->db_connect_id, $query);
112 if($this->query_result)
114 return $this->query_result;
116 else
118 return ( $transaction == 'END_TRANSACTION' ) ? true : false;
122 function sql_select_db($dbname)
124 if($this->db_connect_id)
126 $result = mysqli_select_db($this->db_connect_id, $dbname);
127 return $result;
129 return false;
131 function sql_reselect_db()
133 if($this->db_connect_id)
135 $result = mysqli_select_db($this->db_connect_id, $this->dbname);
136 return $result;
138 return false;
141 // Other query methods
143 function sql_numrows($query_id = 0)
145 if(!$query_id)
147 $query_id = $this->query_result;
149 if($query_id)
151 $result = mysqli_num_rows($query_id);
152 return $result;
154 else
156 return false;
159 function sql_affectedrows()
161 if($this->db_connect_id)
163 $result = mysqli_affected_rows($this->db_connect_id);
164 return $result;
166 else
168 return false;
171 function sql_numfields($query_id = 0)
173 if(!$query_id)
175 $query_id = $this->query_result;
177 if($query_id)
179 $result = mysqli_num_fields($query_id);
180 return $result;
182 else
184 return false;
187 // function sql_fieldname($query_id = 0){}
188 // function sql_fieldtype($offset, $query_id = 0){}
189 function sql_fetchrow($query_id = 0)
191 if(!$query_id)
193 $query_id = $this->query_result;
195 if($query_id)
197 return mysqli_fetch_array($query_id);
199 else
201 return false;
204 function sql_fetchrowset($query_id = 0)
206 if(!$query_id)
208 $query_id = $this->query_result;
210 if($query_id)
212 while($row = mysqli_fetch_array($query_id))
214 $result[] = $row;
216 return $result;
218 else
220 return false;
223 // function sql_fetchfield($field, $rownum = -1, $query_id = 0){}
224 // function sql_rowseek($rownum, $query_id = 0){}
225 function sql_nextid(){
226 if($this->db_connect_id)
228 $result = mysqli_insert_id($this->db_connect_id);
229 return $result;
231 else
233 return false;
236 function sql_freeresult($query_id = 0){
237 if(!$query_id)
239 $query_id = $this->query_result;
242 if ( $query_id )
244 @mysqli_free_result($query_id);
246 return true;
248 else
250 return false;
253 function sql_escape_string($str)
255 return mysqli_real_escape_string($this->db_connect_id, $str);
257 function sql_error($query_id = 0)
259 $result["message"] = mysqli_error($this->db_connect_id);
260 $result["code"] = mysqli_errno($this->db_connect_id);
262 return $result;
265 } // class sql_db
267 class sql_db_string extends sql_db
270 // Constructor ($connstring format : mysql://user:password@host/dbname)
272 function __construct($connstring, $persistency = true)
274 $ret = false;
275 if ($connstring != '')
277 if (preg_match("#^mysqli?://([^:]+)(?::([^@]*))?@([^\\/]+)/([^/]+)[/]?$#", $connstring, $params))
279 $sqlserver = $params[3];
280 $sqluser = $params[1];
281 $sqlpassword = $params[2];
282 $database = $params[4];
284 $ret = parent::__construct($sqlserver, $sqluser, $sqlpassword, $database, $persistency);
287 return $ret;
289 } // class sql_db_string
292 } // if ... define