1 |
4
|
ryan
|
<?php
|
2 |
1362
|
Luisehahne
|
/**
|
3 |
1866
|
Luisehahne
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
|
4 |
1362
|
Luisehahne
|
*
|
5 |
1866
|
Luisehahne
|
* This program is free software: you can redistribute it and/or modify
|
6 |
|
|
* it under the terms of the GNU General Public License as published by
|
7 |
|
|
* the Free Software Foundation, either version 3 of the License, or
|
8 |
|
|
* (at your option) any later version.
|
9 |
1362
|
Luisehahne
|
*
|
10 |
1866
|
Luisehahne
|
* This program is distributed in the hope that it will be useful,
|
11 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
|
|
* GNU General Public License for more details.
|
14 |
|
|
*
|
15 |
|
|
* You should have received a copy of the GNU General Public License
|
16 |
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
17 |
1362
|
Luisehahne
|
*/
|
18 |
1866
|
Luisehahne
|
/**
|
19 |
|
|
* WbDatabase.php
|
20 |
|
|
*
|
21 |
|
|
* @category Core
|
22 |
|
|
* @package Core_database
|
23 |
1998
|
darkviper
|
* @author Manuela v.d.Decken <manuela@isteam.de>
|
24 |
|
|
* @copyright Manuela v.d.Decken <manuela@isteam.de>
|
25 |
1866
|
Luisehahne
|
* @license http://www.gnu.org/licenses/gpl.html GPL License
|
26 |
2127
|
darkviper
|
* @version 0.1.1
|
27 |
1866
|
Luisehahne
|
* @revision $Revision$
|
28 |
|
|
* @lastmodified $Date$
|
29 |
2127
|
darkviper
|
* @description Mysqli database wrapper for use with websitebaker version 2.8.4
|
30 |
1866
|
Luisehahne
|
*/
|
31 |
|
|
|
32 |
1496
|
DarkViper
|
/* -------------------------------------------------------- */
|
33 |
1885
|
Luisehahne
|
@define('DATABASE_CLASS_LOADED', true);
|
34 |
4
|
ryan
|
|
35 |
2127
|
darkviper
|
define('MYSQLI_SEEK_LAST', -1);
|
36 |
|
|
define('MYSQLI_SEEK_FIRST', 0);
|
37 |
|
|
/* define the old mysql consts for Backward compatibility */
|
38 |
|
|
if (!defined('MYSQL_ASSOC'))
|
39 |
|
|
{
|
40 |
|
|
define('MYSQL_SEEK_LAST', -1);
|
41 |
|
|
define('MYSQL_SEEK_FIRST', 0);
|
42 |
|
|
define('MYSQL_ASSOC', 1);
|
43 |
|
|
define('MYSQL_NUM', 2);
|
44 |
|
|
define('MYSQL_BOTH', 3);
|
45 |
|
|
define('MYSQL_CLIENT_COMPRESS', 32);
|
46 |
|
|
define('MYSQL_CLIENT_IGNORE_SPACE', 256);
|
47 |
|
|
define('MYSQL_CLIENT_INTERACTIVE', 1024);
|
48 |
|
|
define('MYSQL_CLIENT_SSL', 2048);
|
49 |
|
|
}
|
50 |
|
|
|
51 |
2120
|
darkviper
|
class WbDatabase extends WbDatabaseHelper {
|
52 |
1763
|
Luisehahne
|
|
53 |
2127
|
darkviper
|
private static $_oInstances = array();
|
54 |
1680
|
darkviper
|
|
55 |
2127
|
darkviper
|
protected $oDbHandle = null; // readonly from outside
|
56 |
|
|
protected $sDbName = '';
|
57 |
|
|
protected $sInstanceIdentifier = '';
|
58 |
|
|
protected $sTablePrefix = '';
|
59 |
|
|
protected $sCharset = '';
|
60 |
|
|
protected $connected = false;
|
61 |
|
|
protected $error = '';
|
62 |
|
|
protected $error_type = '';
|
63 |
|
|
protected $iQueryCount = 0;
|
64 |
1362
|
Luisehahne
|
|
65 |
1998
|
darkviper
|
/**
|
66 |
|
|
* __constructor
|
67 |
|
|
* prevent from public instancing
|
68 |
|
|
*/
|
69 |
2127
|
darkviper
|
final private function __construct() {}
|
70 |
1998
|
darkviper
|
/**
|
71 |
|
|
* prevent from cloning
|
72 |
|
|
*/
|
73 |
2127
|
darkviper
|
final private function __clone() {}
|
74 |
1683
|
darkviper
|
/**
|
75 |
1686
|
darkviper
|
* get a valid instance of this class
|
76 |
|
|
* @param string $sIdentifier selector for several different instances
|
77 |
1998
|
darkviper
|
* @return WbDatabase object
|
78 |
1686
|
darkviper
|
*/
|
79 |
2127
|
darkviper
|
final public static function getInstance($sIdentifier = 'core')
|
80 |
|
|
{
|
81 |
|
|
if( !isset(self::$_oInstances[$sIdentifier])) {
|
82 |
1686
|
darkviper
|
$c = __CLASS__;
|
83 |
2127
|
darkviper
|
$oInstance = new $c;
|
84 |
|
|
$oInstance->sInstanceIdentifier = $sIdentifier;
|
85 |
1974
|
darkviper
|
self::$_oInstances[$sIdentifier] = $oInstance;
|
86 |
2127
|
darkviper
|
}
|
87 |
|
|
return self::$_oInstances[$sIdentifier];
|
88 |
|
|
}
|
89 |
1686
|
darkviper
|
/**
|
90 |
|
|
* disconnect and kills an existing instance
|
91 |
1998
|
darkviper
|
* @param string $sIdentifier selector for instance to kill
|
92 |
1686
|
darkviper
|
*/
|
93 |
2127
|
darkviper
|
final public static function killInstance($sIdentifier)
|
94 |
|
|
{
|
95 |
|
|
if($sIdentifier != 'core') {
|
96 |
|
|
if( isset(self::$_oInstances[$sIdentifier])) {
|
97 |
|
|
self::$_oInstances[$sIdentifier]->disconnect();
|
98 |
|
|
unset(self::$_oInstances[$sIdentifier]);
|
99 |
|
|
}
|
100 |
|
|
}
|
101 |
|
|
}
|
102 |
1686
|
darkviper
|
/**
|
103 |
1998
|
darkviper
|
* Establish connection
|
104 |
1683
|
darkviper
|
* @param string $url
|
105 |
|
|
* @return bool
|
106 |
1998
|
darkviper
|
* @throws WbDatabaseException
|
107 |
|
|
* @description opens a connection using connect URL<br />
|
108 |
|
|
* Example for SQL-Url: 'mysql://user:password@example.com[:3306]/database?charset=utf8&tableprefix=xx_'
|
109 |
1683
|
darkviper
|
*/
|
110 |
2127
|
darkviper
|
public function doConnect($url = '')
|
111 |
|
|
{
|
112 |
|
|
if ($this->connected) { return $this->connected; } // prevent from reconnecting
|
113 |
|
|
$this->connected = false;
|
114 |
|
|
if ($url != '') {
|
115 |
|
|
// parse URL and extract connection data
|
116 |
|
|
$aIni = parse_url($url);
|
117 |
|
|
$scheme = isset($aIni['scheme']) ? $aIni['scheme'] : 'mysqli';
|
118 |
|
|
$hostname = isset($aIni['host']) ? $aIni['host'] : '';
|
119 |
|
|
$username = isset($aIni['user']) ? $aIni['user'] : '';
|
120 |
|
|
$password = isset($aIni['pass']) ? $aIni['pass'] : '';
|
121 |
|
|
$hostport = isset($aIni['port']) ? $aIni['port'] : '3306';
|
122 |
|
|
$hostport = $hostport == '3306' ? null : $hostport;
|
123 |
|
|
$db_name = ltrim(isset($aIni['path']) ? $aIni['path'] : '', '/\\');
|
124 |
|
|
$sTmp = isset($aIni['query']) ? $aIni['query'] : '';
|
125 |
|
|
$aQuery = explode('&', $sTmp);
|
126 |
|
|
foreach ($aQuery as $sArgument) {
|
127 |
|
|
$aArg = explode('=', $sArgument);
|
128 |
|
|
switch (strtolower($aArg[0])) {
|
129 |
|
|
case 'charset':
|
130 |
|
|
$this->sCharset = strtolower(preg_replace('/[^a-z0-9]/i', '', $aArg[1]));
|
131 |
|
|
break;
|
132 |
|
|
case 'tableprefix':
|
133 |
|
|
$this->sTablePrefix = $aArg[1];
|
134 |
|
|
break;
|
135 |
|
|
default:
|
136 |
|
|
break;
|
137 |
|
|
}
|
138 |
|
|
}
|
139 |
|
|
$this->sDbName = $db_name;
|
140 |
|
|
} else {
|
141 |
|
|
throw new WbDatabaseException('Missing parameter: unable to connect database');
|
142 |
|
|
}
|
143 |
|
|
$this->oDbHandle = @mysqli_connect($hostname, $username, $password, $db_name, $hostport);
|
144 |
|
|
if (!$this->oDbHandle) {
|
145 |
|
|
throw new WbDatabaseException('unable to connect \''.$scheme.'://'.$hostname.':'.$hostport.'\'');
|
146 |
|
|
} else {
|
147 |
2104
|
darkviper
|
if ($this->sCharset) {
|
148 |
2120
|
darkviper
|
@mysqli_query($this->oDbHandle, 'SET NAMES '.$this->sCharset);
|
149 |
|
|
mysqli_set_charset($this->oDbHandle, $this->sCharset);
|
150 |
2104
|
darkviper
|
}
|
151 |
|
|
$this->connected = true;
|
152 |
2127
|
darkviper
|
}
|
153 |
|
|
return $this->connected;
|
154 |
|
|
}
|
155 |
1998
|
darkviper
|
/**
|
156 |
|
|
* disconnect database
|
157 |
|
|
* @return bool
|
158 |
|
|
* @description Disconnect current object from the database<br />
|
159 |
|
|
* the 'core' connection can NOT be disconnected!
|
160 |
|
|
*/
|
161 |
2127
|
darkviper
|
public function disconnect()
|
162 |
|
|
{
|
163 |
|
|
if ($this->connected == true && $oInstance->sInstanceIdentifier != 'core') {
|
164 |
|
|
mysqli_close($this->oDbHandle);
|
165 |
|
|
$this->connected = false;
|
166 |
|
|
return true;
|
167 |
|
|
}
|
168 |
|
|
return false;
|
169 |
|
|
}
|
170 |
1998
|
darkviper
|
/**
|
171 |
|
|
* Alias for doQuery()
|
172 |
2127
|
darkviper
|
* @deprecated from WB-2.8.4 and higher
|
173 |
1998
|
darkviper
|
*/
|
174 |
2127
|
darkviper
|
public function query($statement)
|
175 |
|
|
{
|
176 |
|
|
trigger_error('Deprecated function call: '.__CLASS__.'::'.__METHOD__, E_USER_DEPRECATED);
|
177 |
|
|
return $this->doQuery($statement);
|
178 |
|
|
}
|
179 |
1998
|
darkviper
|
/**
|
180 |
|
|
* execute query
|
181 |
|
|
* @param string $statement the SQL-statement to execute
|
182 |
|
|
* @return null|\mysql
|
183 |
|
|
*/
|
184 |
2127
|
darkviper
|
public function doQuery($statement) {
|
185 |
|
|
$oRetval = null;
|
186 |
|
|
$this->iQueryCount++;
|
187 |
|
|
$mysql = new mysql($this->oDbHandle, $statement);
|
188 |
|
|
$this->set_error($mysql->error($this->oDbHandle));
|
189 |
|
|
if (!$mysql->error()) {
|
190 |
|
|
$oRetval = $mysql;
|
191 |
|
|
}
|
192 |
|
|
$this->set_error($mysql->error($this->oDbHandle));
|
193 |
|
|
return $oRetval;
|
194 |
|
|
}
|
195 |
1998
|
darkviper
|
/**
|
196 |
|
|
* Alias for getOne()
|
197 |
2127
|
darkviper
|
* @deprecated from WB-2.8.4 and higher
|
198 |
1998
|
darkviper
|
*/
|
199 |
2127
|
darkviper
|
public function get_one( $statement )
|
200 |
|
|
{
|
201 |
|
|
trigger_error('Deprecated function call: '.__CLASS__.'::'.__METHOD__, E_USER_DEPRECATED);
|
202 |
|
|
return $this->getOne($statement);
|
203 |
|
|
}
|
204 |
|
|
// Gets the first column of the first row
|
205 |
1998
|
darkviper
|
/**
|
206 |
|
|
* Gets the first column of the first row
|
207 |
|
|
* @param string $statement SQL-statement
|
208 |
|
|
* @return null|mixed
|
209 |
|
|
*/
|
210 |
2127
|
darkviper
|
public function getOne( $sStatement )
|
211 |
|
|
{
|
212 |
|
|
$sRetval = null;
|
213 |
|
|
if (($oRecSet = $this->doQuery($sStatement))) {
|
214 |
|
|
if (($aRecord = $oRecSet->fetchArray(MYSQL_NUM))) {
|
215 |
|
|
$sRetval = $aRecord[0];
|
216 |
|
|
}
|
217 |
|
|
}
|
218 |
|
|
return ($this->isError() ? null : $sRetval);
|
219 |
|
|
}
|
220 |
1998
|
darkviper
|
/**
|
221 |
|
|
* Alias for setError()
|
222 |
2127
|
darkviper
|
* @deprecated from WB-2.8.4 and higher
|
223 |
1998
|
darkviper
|
*/
|
224 |
2127
|
darkviper
|
public function set_error($message = null)
|
225 |
|
|
{
|
226 |
|
|
trigger_error('Deprecated function call: '.__CLASS__.'::'.__METHOD__, E_USER_DEPRECATED);
|
227 |
|
|
$this->setError($message = null);
|
228 |
|
|
}
|
229 |
|
|
// Set the DB error
|
230 |
1998
|
darkviper
|
/**
|
231 |
|
|
* setError
|
232 |
|
|
* @param string $message
|
233 |
|
|
*/
|
234 |
2127
|
darkviper
|
public function setError($message = null)
|
235 |
|
|
{
|
236 |
|
|
$this->error = $message;
|
237 |
|
|
}
|
238 |
1998
|
darkviper
|
/**
|
239 |
|
|
* Alias for isError
|
240 |
2127
|
darkviper
|
* @deprecated from WB-2.8.4 and higher
|
241 |
1998
|
darkviper
|
*/
|
242 |
2127
|
darkviper
|
public function is_error()
|
243 |
|
|
{
|
244 |
|
|
trigger_error('Deprecated function call: '.__CLASS__.'::'.__METHOD__, E_USER_DEPRECATED);
|
245 |
|
|
return $this->isError();
|
246 |
|
|
}
|
247 |
1998
|
darkviper
|
/**
|
248 |
|
|
* isError
|
249 |
|
|
* @return bool
|
250 |
|
|
*/
|
251 |
2127
|
darkviper
|
public function isError()
|
252 |
|
|
{
|
253 |
|
|
return (!empty($this->error)) ? true : false;
|
254 |
|
|
}
|
255 |
1998
|
darkviper
|
/**
|
256 |
|
|
* Alias for getError
|
257 |
2127
|
darkviper
|
* @deprecated from WB-2.8.4 and higher
|
258 |
1998
|
darkviper
|
*/
|
259 |
2127
|
darkviper
|
public function get_error()
|
260 |
|
|
{
|
261 |
|
|
trigger_error('Deprecated function call: '.__CLASS__.'::'.__METHOD__, E_USER_DEPRECATED);
|
262 |
|
|
return $this->getError();
|
263 |
|
|
}
|
264 |
1998
|
darkviper
|
/**
|
265 |
|
|
* get last Error
|
266 |
|
|
* @return string
|
267 |
|
|
*/
|
268 |
2127
|
darkviper
|
public function getError()
|
269 |
|
|
{
|
270 |
|
|
return $this->error;
|
271 |
|
|
}
|
272 |
1613
|
darkviper
|
/**
|
273 |
1885
|
Luisehahne
|
* Protect class from property injections
|
274 |
|
|
* @param string name of property
|
275 |
|
|
* @param mixed value
|
276 |
|
|
* @throws WbDatabaseException
|
277 |
2127
|
darkviper
|
*/
|
278 |
|
|
public function __set($name, $value)
|
279 |
|
|
{
|
280 |
|
|
throw new WbDatabaseException('tried to set a readonly or nonexisting property ['.$name.']!! ');
|
281 |
|
|
}
|
282 |
1866
|
Luisehahne
|
/**
|
283 |
1613
|
darkviper
|
* default Getter for some properties
|
284 |
1866
|
Luisehahne
|
* @param string name of the Property
|
285 |
1998
|
darkviper
|
* @return NULL on error | valid property
|
286 |
1362
|
Luisehahne
|
*/
|
287 |
2127
|
darkviper
|
public function __get($sPropertyName)
|
288 |
|
|
{
|
289 |
|
|
switch ($sPropertyName) {
|
290 |
|
|
case 'getDbHandle': // << set deprecated
|
291 |
|
|
case 'db_handle': // << set deprecated
|
292 |
|
|
trigger_error('Deprecated property call: '.__CLASS__.'::'.__METHOD__.'(getDbHandle|db_handle)', E_USER_DEPRECATED);
|
293 |
|
|
case 'DbHandle':
|
294 |
|
|
$retval = $this->oDbHandle;
|
295 |
|
|
break;
|
296 |
|
|
case 'getLastInsertId': // << set deprecated
|
297 |
|
|
trigger_error('Deprecated property call: '.__CLASS__.'::'.__METHOD__.'(getLastInsertId)', E_USER_DEPRECATED);
|
298 |
|
|
case 'LastInsertId':
|
299 |
|
|
$retval = $this->getLastInsertId();
|
300 |
|
|
break;
|
301 |
|
|
case 'getDbName': // << set deprecated
|
302 |
|
|
case 'db_name': // << set deprecated
|
303 |
|
|
trigger_error('Deprecated property call: '.__CLASS__.'::'.__METHOD__.'(getDbName|db_name)', E_USER_DEPRECATED);
|
304 |
|
|
case 'DbName':
|
305 |
|
|
$retval = $this->sDbName;
|
306 |
|
|
break;
|
307 |
|
|
case 'getTablePrefix': // << set deprecated
|
308 |
|
|
trigger_error('Deprecated property call: '.__CLASS__.'::'.__METHOD__.'(getTablePrefix)', E_USER_DEPRECATED);
|
309 |
|
|
case 'TablePrefix':
|
310 |
|
|
$retval = $this->sTablePrefix;
|
311 |
|
|
break;
|
312 |
|
|
case 'getQueryCount': // << set deprecated
|
313 |
|
|
trigger_error('Deprecated property call: '.__CLASS__.'::'.__METHOD__.'(getQueryCount)', E_USER_DEPRECATED);
|
314 |
|
|
case 'QueryCount':
|
315 |
|
|
$retval = $this->iQueryCount;
|
316 |
|
|
break;
|
317 |
|
|
default:
|
318 |
|
|
$retval = null;
|
319 |
|
|
break;
|
320 |
|
|
}
|
321 |
|
|
return $retval;
|
322 |
|
|
} // __get()
|
323 |
1885
|
Luisehahne
|
/**
|
324 |
|
|
* Escapes special characters in a string for use in an SQL statement
|
325 |
|
|
* @param string $unescaped_string
|
326 |
|
|
* @return string
|
327 |
|
|
*/
|
328 |
2127
|
darkviper
|
public function escapeString($sUnescapedString)
|
329 |
|
|
{
|
330 |
|
|
return mysqli_real_escape_string($this->oDbHandle, $sUnescapedString);
|
331 |
|
|
}
|
332 |
1885
|
Luisehahne
|
/**
|
333 |
2127
|
darkviper
|
* Escapes wildchar characters in a string for use in an SQL-LIKE statement
|
334 |
|
|
* @param string $unescaped_string
|
335 |
|
|
* @return string
|
336 |
|
|
*/
|
337 |
|
|
public function escapeLike($sUnescapedString)
|
338 |
|
|
{
|
339 |
|
|
return addcslashes($sUnescapedString, '_%');
|
340 |
|
|
}
|
341 |
|
|
/**
|
342 |
1885
|
Luisehahne
|
* Last inserted Id
|
343 |
|
|
* @return bool|int false on error, 0 if no record inserted
|
344 |
2127
|
darkviper
|
*/
|
345 |
|
|
public function getLastInsertId()
|
346 |
|
|
{
|
347 |
|
|
return mysqli_insert_id($this->oDbHandle);
|
348 |
|
|
}
|
349 |
1362
|
Luisehahne
|
|
350 |
|
|
} /// end of class database
|
351 |
1885
|
Luisehahne
|
// //////////////////////////////////////////////////////////////////////////////////// //
|
352 |
|
|
/**
|
353 |
|
|
* WbDatabaseException
|
354 |
|
|
*
|
355 |
|
|
* @category Core
|
356 |
|
|
* @package Core_database
|
357 |
1998
|
darkviper
|
* @author Manuela v.d.Decken <manuela@isteam.de>
|
358 |
|
|
* @copyright Manuela v.d.Decken <manuela@isteam.de>
|
359 |
1885
|
Luisehahne
|
* @license http://www.gnu.org/licenses/gpl.html GPL License
|
360 |
|
|
* @version 2.9.0
|
361 |
|
|
* @revision $Revision$
|
362 |
|
|
* @lastmodified $Date$
|
363 |
|
|
* @description Exceptionhandler for the WbDatabase and depending classes
|
364 |
|
|
*/
|
365 |
|
|
class WbDatabaseException extends AppException {}
|
366 |
1362
|
Luisehahne
|
|
367 |
1998
|
darkviper
|
/**
|
368 |
|
|
* mysql
|
369 |
|
|
*
|
370 |
|
|
* @category Core
|
371 |
|
|
* @package Core_database
|
372 |
|
|
* @author Manuela v.d.Decken <manuela@isteam.de>
|
373 |
|
|
* @copyright Manuela v.d.Decken <manuela@isteam.de>
|
374 |
|
|
* @license http://www.gnu.org/licenses/gpl.html GPL License
|
375 |
|
|
* @version 2.9.0
|
376 |
|
|
* @revision $Revision$
|
377 |
|
|
* @lastmodified $Date$
|
378 |
|
|
* @description MYSQL result object for requests
|
379 |
|
|
*
|
380 |
|
|
*/
|
381 |
4
|
ryan
|
class mysql {
|
382 |
|
|
|
383 |
2127
|
darkviper
|
private $result = null;
|
384 |
|
|
private $oDbHandle = null;
|
385 |
2104
|
darkviper
|
private $error = '';
|
386 |
1998
|
darkviper
|
|
387 |
2127
|
darkviper
|
public function __construct($oHandle, $sStatement)
|
388 |
2104
|
darkviper
|
{
|
389 |
|
|
$this->oDbHandle = $oHandle;
|
390 |
2127
|
darkviper
|
$this->query($sStatement);
|
391 |
2104
|
darkviper
|
}
|
392 |
1998
|
darkviper
|
/**
|
393 |
|
|
* query sql statement
|
394 |
|
|
* @param string $statement
|
395 |
|
|
* @return object
|
396 |
|
|
* @throws WbDatabaseException
|
397 |
|
|
*/
|
398 |
2127
|
darkviper
|
public function query($sStatement)
|
399 |
|
|
{
|
400 |
|
|
$this->result = @mysqli_query($this->oDbHandle, $sStatement);
|
401 |
|
|
if ($this->result === false) {
|
402 |
|
|
if (DEBUG) {
|
403 |
|
|
throw new WbDatabaseException(mysqli_error($this->oDbHandle));
|
404 |
|
|
} else {
|
405 |
|
|
throw new WbDatabaseException('Error in SQL-Statement');
|
406 |
|
|
}
|
407 |
|
|
}
|
408 |
|
|
$this->error = mysqli_error($this->oDbHandle);
|
409 |
|
|
return $this->result;
|
410 |
|
|
}
|
411 |
1998
|
darkviper
|
/**
|
412 |
|
|
* numRows
|
413 |
|
|
* @return integer
|
414 |
|
|
* @description number of returned records
|
415 |
|
|
*/
|
416 |
2127
|
darkviper
|
public function numRows()
|
417 |
|
|
{
|
418 |
|
|
return mysqli_num_rows($this->result);
|
419 |
|
|
}
|
420 |
1998
|
darkviper
|
/**
|
421 |
|
|
* fetchRow
|
422 |
2127
|
darkviper
|
* @param int $typ MYSQL_BOTH(default) | MYSQL_ASSOC | MYSQL_NUM // DEPRECATED
|
423 |
|
|
* @return array with numeric indexes
|
424 |
1998
|
darkviper
|
* @description get current record and increment pointer
|
425 |
|
|
*/
|
426 |
2127
|
darkviper
|
public function fetchRow($typ = MYSQLI_BOTH)
|
427 |
|
|
{
|
428 |
|
|
if ($typ != MYSQLI_NUM) {
|
429 |
|
|
trigger_error('Deprecated call: '.__CLASS__.'::'.__METHOD__.' for MYSQLI_ASSOC|MYSQL_BOTH', E_USER_DEPRECATED);
|
430 |
|
|
return mysqli_fetch_array($this->result, $typ);
|
431 |
|
|
} else {
|
432 |
|
|
return mysqli_fetch_row($this->result);
|
433 |
|
|
}
|
434 |
|
|
}
|
435 |
1998
|
darkviper
|
/**
|
436 |
2127
|
darkviper
|
* fetchAssoc
|
437 |
|
|
* @return array with assotiative indexes
|
438 |
|
|
* @description get current record and increment pointer
|
439 |
|
|
*/
|
440 |
|
|
public function fetchAssoc()
|
441 |
|
|
{
|
442 |
2128
|
darkviper
|
return mysqli_fetch_row($this->result);
|
443 |
|
|
}
|
444 |
|
|
/**
|
445 |
|
|
* fetchArray
|
446 |
|
|
* @param int $iType MYSQL_ASSOC(default) | MYSQL_BOTH | MYSQL_NUM
|
447 |
|
|
* @return array of current record
|
448 |
|
|
* @description get current record and increment pointer
|
449 |
|
|
*/
|
450 |
|
|
public function fetchArray($iType = MYSQLI_ASSOC)
|
451 |
|
|
{
|
452 |
|
|
if ($iType < MYSQLI_ASSOC || $iType > MYSQLI_BOTH) {
|
453 |
|
|
$iType = MYSQLI_ASSOC;
|
454 |
2127
|
darkviper
|
}
|
455 |
2128
|
darkviper
|
return mysqli_fetch_array($this->result, $iType);
|
456 |
2127
|
darkviper
|
}
|
457 |
|
|
/**
|
458 |
1998
|
darkviper
|
* fetchObject
|
459 |
|
|
* @param string $sClassname Name of the class to use. Is no given use stdClass
|
460 |
|
|
* @param string $aParams optional array of arguments for the constructor
|
461 |
|
|
* @return object
|
462 |
|
|
* @description get current record as an object and increment pointer
|
463 |
|
|
*/
|
464 |
2127
|
darkviper
|
public function fetchObject($sClassName = null, array $aParams = null)
|
465 |
|
|
{
|
466 |
|
|
if ($sClassName === null || class_exists($sClassName)) {
|
467 |
|
|
return mysqli_fetch_object($this->result, $sClassName, $aParams);
|
468 |
|
|
} else {
|
469 |
|
|
throw new WbDatabaseException('Class <'.$sClassName.'> not available on request of mysqli_fetch_object()');
|
470 |
|
|
}
|
471 |
|
|
}
|
472 |
1998
|
darkviper
|
/**
|
473 |
2120
|
darkviper
|
* fetchAll
|
474 |
|
|
* @param int $iType MYSQL_ASSOC(default) | MYSQL_NUM
|
475 |
|
|
* @return array of rows
|
476 |
|
|
* @description get all records of the result set
|
477 |
|
|
*/
|
478 |
2127
|
darkviper
|
public function fetchAll($iType = MYSQLI_ASSOC)
|
479 |
2120
|
darkviper
|
{
|
480 |
2127
|
darkviper
|
$iType = $iType != MYSQLI_NUM ? MYSQL_ASSOC : MYSQLI_NUM;
|
481 |
2120
|
darkviper
|
return mysqli_fetch_all($this->result, $iType);
|
482 |
|
|
}
|
483 |
|
|
/**
|
484 |
1998
|
darkviper
|
* rewind
|
485 |
|
|
* @return bool
|
486 |
|
|
* @description set the recordpointer to the first record || false on error
|
487 |
|
|
*/
|
488 |
2127
|
darkviper
|
public function rewind()
|
489 |
|
|
{
|
490 |
|
|
return $this->seekRow(MYSQLI_SEEK_FIRST);
|
491 |
|
|
}
|
492 |
1998
|
darkviper
|
/**
|
493 |
|
|
* seekRow
|
494 |
2127
|
darkviper
|
* @param int $position also can be MYSQLI_SEEK_FIRST||MYSQLI_SEEK_LAST
|
495 |
1998
|
darkviper
|
* @return bool
|
496 |
|
|
* @description set the pointer to the given record || false on error
|
497 |
|
|
*/
|
498 |
2127
|
darkviper
|
public function seekRow( $position = MYSQLI_SEEK_FIRST )
|
499 |
|
|
{
|
500 |
|
|
$pmax = $this->numRows() - 1;
|
501 |
|
|
$p = (($position < 0 || $position > $pmax) ? $pmax : $position);
|
502 |
|
|
return mysqli_data_seek($this->result, $p);
|
503 |
|
|
}
|
504 |
1998
|
darkviper
|
/**
|
505 |
|
|
* freeResult
|
506 |
|
|
* @return bool
|
507 |
|
|
* @description remove retult object from memeory
|
508 |
|
|
*/
|
509 |
2127
|
darkviper
|
public function freeResult()
|
510 |
|
|
{
|
511 |
|
|
return mysqli_free_result($this->result);
|
512 |
|
|
}
|
513 |
|
|
/**
|
514 |
1998
|
darkviper
|
* Get error
|
515 |
|
|
* @return string || null if no error
|
516 |
|
|
*/
|
517 |
2127
|
darkviper
|
public function error()
|
518 |
|
|
{
|
519 |
|
|
if (isset($this->error)) {
|
520 |
|
|
return $this->error;
|
521 |
|
|
} else {
|
522 |
|
|
return null;
|
523 |
|
|
}
|
524 |
|
|
}
|
525 |
4
|
ryan
|
|
526 |
|
|
}
|