blob: e953db052b0a87df34107c5b3e707b7b57836f23 [file] [log] [blame]
Andrey Andreevc5536aa2012-11-01 17:33:58 +02001<?php
Derek Allard2067d1a2008-11-13 22:59:24 +00002/**
3 * CodeIgniter
4 *
Andrey Andreevfe9309d2015-01-09 17:48:58 +02005 * An open source application development framework for PHP
Derek Allard2067d1a2008-11-13 22:59:24 +00006 *
Andrey Andreevbdb96ca2014-10-28 00:13:31 +02007 * This content is released under the MIT License (MIT)
Andrey Andreev1ff49e02012-01-27 11:30:41 +02008 *
Andrey Andreevfe9309d2015-01-09 17:48:58 +02009 * Copyright (c) 2014 - 2015, British Columbia Institute of Technology
Andrey Andreev1ff49e02012-01-27 11:30:41 +020010 *
Andrey Andreevbdb96ca2014-10-28 00:13:31 +020011 * Permission is hereby granted, free of charge, to any person obtaining a copy
12 * of this software and associated documentation files (the "Software"), to deal
13 * in the Software without restriction, including without limitation the rights
14 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 * copies of the Software, and to permit persons to whom the Software is
16 * furnished to do so, subject to the following conditions:
Derek Jonesf4a4bd82011-10-20 12:18:42 -050017 *
Andrey Andreevbdb96ca2014-10-28 00:13:31 +020018 * The above copyright notice and this permission notice shall be included in
19 * all copies or substantial portions of the Software.
20 *
21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
27 * THE SOFTWARE.
28 *
29 * @package CodeIgniter
30 * @author EllisLab Dev Team
darwinel871754a2014-02-11 17:34:57 +010031 * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (http://ellislab.com/)
Andrey Andreevfe9309d2015-01-09 17:48:58 +020032 * @copyright Copyright (c) 2014 - 2015, British Columbia Institute of Technology (http://bcit.ca/)
Andrey Andreevbdb96ca2014-10-28 00:13:31 +020033 * @license http://opensource.org/licenses/MIT MIT License
34 * @link http://codeigniter.com
35 * @since Version 1.3.0
Derek Allard2067d1a2008-11-13 22:59:24 +000036 * @filesource
37 */
Andrey Andreevc5536aa2012-11-01 17:33:58 +020038defined('BASEPATH') OR exit('No direct script access allowed');
Derek Allard2067d1a2008-11-13 22:59:24 +000039
Derek Allard2067d1a2008-11-13 22:59:24 +000040/**
Andrey Andreev1ff49e02012-01-27 11:30:41 +020041 * MySQLi Database Adapter Class
Derek Allard2067d1a2008-11-13 22:59:24 +000042 *
43 * Note: _DB is an extender class that the app controller
Jamie Rumbelow7efad202012-02-19 12:37:00 +000044 * creates dynamically based on whether the query builder
Derek Allard2067d1a2008-11-13 22:59:24 +000045 * class is being used or not.
46 *
47 * @package CodeIgniter
48 * @subpackage Drivers
49 * @category Database
Derek Jonesf4a4bd82011-10-20 12:18:42 -050050 * @author EllisLab Dev Team
Derek Allard2067d1a2008-11-13 22:59:24 +000051 * @link http://codeigniter.com/user_guide/database/
52 */
53class CI_DB_mysqli_driver extends CI_DB {
54
Andrey Andreeva24e52e2012-11-02 03:54:12 +020055 /**
56 * Database driver
57 *
58 * @var string
59 */
Andrey Andreev1ff49e02012-01-27 11:30:41 +020060 public $dbdriver = 'mysqli';
Derek Allard2067d1a2008-11-13 22:59:24 +000061
62 /**
Andrey Andreeva24e52e2012-11-02 03:54:12 +020063 * Compression flag
64 *
65 * @var bool
66 */
67 public $compress = FALSE;
68
69 /**
70 * DELETE hack flag
71 *
Derek Allard2067d1a2008-11-13 22:59:24 +000072 * Whether to use the MySQL "delete hack" which allows the number
73 * of affected rows to be shown. Uses a preg_replace when enabled,
74 * adding a bit more processing to all queries.
Andrey Andreeva24e52e2012-11-02 03:54:12 +020075 *
76 * @var bool
Barry Mienydd671972010-10-04 16:33:58 +020077 */
Andrey Andreev1ff49e02012-01-27 11:30:41 +020078 public $delete_hack = TRUE;
Derek Allard2067d1a2008-11-13 22:59:24 +000079
Andrey Andreevf8f14f32013-12-10 11:32:32 +020080 /**
81 * Strict ON flag
82 *
83 * Whether we're running in strict SQL mode.
84 *
85 * @var bool
86 */
87 public $stricton = FALSE;
88
Andrey Andreeva24e52e2012-11-02 03:54:12 +020089 // --------------------------------------------------------------------
90
Derek Allard2067d1a2008-11-13 22:59:24 +000091 /**
Andrey Andreeva24e52e2012-11-02 03:54:12 +020092 * Identifier escape character
Derek Allard2067d1a2008-11-13 22:59:24 +000093 *
Andrey Andreeva24e52e2012-11-02 03:54:12 +020094 * @var string
95 */
96 protected $_escape_char = '`';
97
98 // --------------------------------------------------------------------
99
100 /**
101 * Database connection
102 *
103 * @param bool $persistent
Andrey Andreev1ff49e02012-01-27 11:30:41 +0200104 * @return object
Andrey Andreev2f8bf9b2012-10-12 20:37:52 +0300105 * @todo SSL support
Barry Mienydd671972010-10-04 16:33:58 +0200106 */
Andrey Andreev2f8bf9b2012-10-12 20:37:52 +0300107 public function db_connect($persistent = FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000108 {
Andrey Andreev1fb0cc72014-12-17 19:08:35 +0200109 // Do we have a socket path?
110 if ($this->hostname[0] === '/')
111 {
112 $hostname = NULL;
113 $port = NULL;
114 $socket = $this->hostname;
115 }
116 else
117 {
118 // Persistent connection support was added in PHP 5.3.0
119 $hostname = ($persistent === TRUE && is_php('5.3'))
120 ? 'p:'.$this->hostname : $this->hostname;
121 $port = empty($this->port) ? NULL : $this->port;
122 $socket = NULL;
123 }
124
Andrey Andreev2f8bf9b2012-10-12 20:37:52 +0300125 $client_flags = ($this->compress === TRUE) ? MYSQLI_CLIENT_COMPRESS : 0;
Andrey Andreev37c85d72012-10-13 17:08:45 +0300126 $mysqli = mysqli_init();
Michiel Vugteveenc27721f2012-08-20 18:34:24 +0200127
Andrey Andreev9305a8b2015-01-26 12:09:58 +0200128 $mysqli->options(MYSQLI_OPT_CONNECT_TIMEOUT, 10);
Andrey Andreev9305a8b2015-01-26 12:09:58 +0200129
Andrey Andreevf8f14f32013-12-10 11:32:32 +0200130 if ($this->stricton)
131 {
132 $mysqli->options(MYSQLI_INIT_COMMAND, 'SET SESSION sql_mode="STRICT_ALL_TABLES"');
133 }
134
Andrey Andreev1fb0cc72014-12-17 19:08:35 +0200135 return $mysqli->real_connect($hostname, $this->username, $this->password, $this->database, $port, $socket, $client_flags)
Andrey Andreev2f8bf9b2012-10-12 20:37:52 +0300136 ? $mysqli : FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +0000137 }
138
139 // --------------------------------------------------------------------
140
141 /**
Derek Jones87cbafc2009-02-27 16:29:59 +0000142 * Reconnect
143 *
144 * Keep / reestablish the db connection if no queries have been
145 * sent for a length of time exceeding the server's idle timeout
146 *
Derek Jones87cbafc2009-02-27 16:29:59 +0000147 * @return void
148 */
Andrey Andreev1ff49e02012-01-27 11:30:41 +0200149 public function reconnect()
Derek Jones87cbafc2009-02-27 16:29:59 +0000150 {
Andrey Andreev992f1752012-03-19 16:58:43 +0200151 if ($this->conn_id !== FALSE && $this->conn_id->ping() === FALSE)
Derek Jones87cbafc2009-02-27 16:29:59 +0000152 {
153 $this->conn_id = FALSE;
154 }
155 }
156
157 // --------------------------------------------------------------------
158
159 /**
Derek Allard2067d1a2008-11-13 22:59:24 +0000160 * Select the database
161 *
Andrey Andreeva24e52e2012-11-02 03:54:12 +0200162 * @param string $database
Andrey Andreev1ff49e02012-01-27 11:30:41 +0200163 * @return bool
Barry Mienydd671972010-10-04 16:33:58 +0200164 */
Andrey Andreev11454e02012-02-22 16:05:47 +0200165 public function db_select($database = '')
Derek Allard2067d1a2008-11-13 22:59:24 +0000166 {
Andrey Andreev024ba2d2012-02-24 11:40:36 +0200167 if ($database === '')
168 {
169 $database = $this->database;
170 }
171
mdunischd3ddf972014-05-07 15:00:40 +0200172 if ($this->conn_id->select_db($database))
Andrey Andreev024ba2d2012-02-24 11:40:36 +0200173 {
174 $this->database = $database;
175 return TRUE;
176 }
177
178 return FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +0000179 }
180
181 // --------------------------------------------------------------------
182
183 /**
184 * Set client character set
185 *
Andrey Andreeva24e52e2012-11-02 03:54:12 +0200186 * @param string $charset
Andrey Andreev1ff49e02012-01-27 11:30:41 +0200187 * @return bool
Derek Allard2067d1a2008-11-13 22:59:24 +0000188 */
Andrey Andreev95bd1d12012-03-12 16:22:28 +0200189 protected function _db_set_charset($charset)
Derek Allard2067d1a2008-11-13 22:59:24 +0000190 {
Andrey Andreev4b90a372014-03-10 10:24:24 +0200191 return $this->conn_id->set_charset($charset);
Derek Allard2067d1a2008-11-13 22:59:24 +0000192 }
193
194 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200195
Derek Allard2067d1a2008-11-13 22:59:24 +0000196 /**
Andrey Andreev08856b82012-03-03 03:19:28 +0200197 * Database version number
Derek Allard2067d1a2008-11-13 22:59:24 +0000198 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000199 * @return string
200 */
Andrey Andreev08856b82012-03-03 03:19:28 +0200201 public function version()
Derek Allard2067d1a2008-11-13 22:59:24 +0000202 {
Andrey Andreev2b730372012-11-05 17:01:11 +0200203 if (isset($this->data_cache['version']))
204 {
205 return $this->data_cache['version'];
206 }
Andrey Andreev2b730372012-11-05 17:01:11 +0200207
208 return $this->data_cache['version'] = $this->conn_id->server_info;
Derek Allard2067d1a2008-11-13 22:59:24 +0000209 }
210
211 // --------------------------------------------------------------------
212
213 /**
214 * Execute the query
215 *
Andrey Andreeva24e52e2012-11-02 03:54:12 +0200216 * @param string $sql an SQL query
Andrey Andreev1ff49e02012-01-27 11:30:41 +0200217 * @return mixed
Barry Mienydd671972010-10-04 16:33:58 +0200218 */
Andrey Andreev1ff49e02012-01-27 11:30:41 +0200219 protected function _execute($sql)
Derek Allard2067d1a2008-11-13 22:59:24 +0000220 {
mdunischd3ddf972014-05-07 15:00:40 +0200221 return $this->conn_id->query($this->_prep_query($sql));
Derek Allard2067d1a2008-11-13 22:59:24 +0000222 }
Barry Mienydd671972010-10-04 16:33:58 +0200223
Derek Allard2067d1a2008-11-13 22:59:24 +0000224 // --------------------------------------------------------------------
225
226 /**
227 * Prep the query
228 *
229 * If needed, each database adapter can prep the query string
230 *
Andrey Andreeva24e52e2012-11-02 03:54:12 +0200231 * @param string $sql an SQL query
Derek Allard2067d1a2008-11-13 22:59:24 +0000232 * @return string
Barry Mienydd671972010-10-04 16:33:58 +0200233 */
Andrey Andreev1ff49e02012-01-27 11:30:41 +0200234 protected function _prep_query($sql)
Derek Allard2067d1a2008-11-13 22:59:24 +0000235 {
Andrey Andreev1ff49e02012-01-27 11:30:41 +0200236 // mysqli_affected_rows() returns 0 for "DELETE FROM TABLE" queries. This hack
237 // modifies the query so that it a proper number of affected rows is returned.
238 if ($this->delete_hack === TRUE && preg_match('/^\s*DELETE\s+FROM\s+(\S+)\s*$/i', $sql))
Derek Allard2067d1a2008-11-13 22:59:24 +0000239 {
Andrey Andreevbe999662013-01-10 11:40:09 +0200240 return trim($sql).' WHERE 1=1';
Derek Allard2067d1a2008-11-13 22:59:24 +0000241 }
Barry Mienydd671972010-10-04 16:33:58 +0200242
Derek Allard2067d1a2008-11-13 22:59:24 +0000243 return $sql;
244 }
245
246 // --------------------------------------------------------------------
247
248 /**
249 * Begin Transaction
250 *
Andrey Andreeva24e52e2012-11-02 03:54:12 +0200251 * @param bool $test_mode
Barry Mienydd671972010-10-04 16:33:58 +0200252 * @return bool
253 */
Andrey Andreev1ff49e02012-01-27 11:30:41 +0200254 public function trans_begin($test_mode = FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000255 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000256 // When transactions are nested we only begin/commit/rollback the outermost ones
Andrey Andreev1ff49e02012-01-27 11:30:41 +0200257 if ( ! $this->trans_enabled OR $this->_trans_depth > 0)
Derek Allard2067d1a2008-11-13 22:59:24 +0000258 {
259 return TRUE;
260 }
261
262 // Reset the transaction failure flag.
263 // If the $test_mode flag is set to TRUE transactions will be rolled back
264 // even if the queries produce a successful result.
Andrey Andreev1ff49e02012-01-27 11:30:41 +0200265 $this->_trans_failure = ($test_mode === TRUE);
Derek Allard2067d1a2008-11-13 22:59:24 +0000266
Andrey Andreev3c5ec852013-09-13 15:01:08 +0300267 $this->conn_id->autocommit(FALSE);
268 return is_php('5.5')
269 ? $this->conn_id->begin_transaction()
270 : $this->simple_query('START TRANSACTION'); // can also be BEGIN or BEGIN WORK
Derek Allard2067d1a2008-11-13 22:59:24 +0000271 }
272
273 // --------------------------------------------------------------------
274
275 /**
276 * Commit Transaction
277 *
Barry Mienydd671972010-10-04 16:33:58 +0200278 * @return bool
279 */
Andrey Andreev1ff49e02012-01-27 11:30:41 +0200280 public function trans_commit()
Derek Allard2067d1a2008-11-13 22:59:24 +0000281 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000282 // When transactions are nested we only begin/commit/rollback the outermost ones
Andrey Andreev1ff49e02012-01-27 11:30:41 +0200283 if ( ! $this->trans_enabled OR $this->_trans_depth > 0)
Derek Allard2067d1a2008-11-13 22:59:24 +0000284 {
285 return TRUE;
286 }
287
Andrey Andreev3c5ec852013-09-13 15:01:08 +0300288 if ($this->conn_id->commit())
289 {
290 $this->conn_id->autocommit(TRUE);
291 return TRUE;
292 }
293
294 return FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +0000295 }
296
297 // --------------------------------------------------------------------
298
299 /**
300 * Rollback Transaction
301 *
Barry Mienydd671972010-10-04 16:33:58 +0200302 * @return bool
303 */
Andrey Andreev1ff49e02012-01-27 11:30:41 +0200304 public function trans_rollback()
Derek Allard2067d1a2008-11-13 22:59:24 +0000305 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000306 // When transactions are nested we only begin/commit/rollback the outermost ones
Andrey Andreev1ff49e02012-01-27 11:30:41 +0200307 if ( ! $this->trans_enabled OR $this->_trans_depth > 0)
Derek Allard2067d1a2008-11-13 22:59:24 +0000308 {
309 return TRUE;
310 }
311
Andrey Andreev3c5ec852013-09-13 15:01:08 +0300312 if ($this->conn_id->rollback())
313 {
314 $this->conn_id->autocommit(TRUE);
315 return TRUE;
316 }
317
318 return FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +0000319 }
320
321 // --------------------------------------------------------------------
322
323 /**
Andrey Andreev0b6a4922013-01-10 16:53:44 +0200324 * Platform-dependant string escape
Derek Allard2067d1a2008-11-13 22:59:24 +0000325 *
Andrey Andreev0b6a4922013-01-10 16:53:44 +0200326 * @param string
Derek Allard2067d1a2008-11-13 22:59:24 +0000327 * @return string
328 */
Andrey Andreev0b6a4922013-01-10 16:53:44 +0200329 protected function _escape_str($str)
Derek Allard2067d1a2008-11-13 22:59:24 +0000330 {
Andrey Andreev62fad282014-06-19 15:25:40 +0300331 return $this->conn_id->real_escape_string($str);
Derek Allard2067d1a2008-11-13 22:59:24 +0000332 }
Barry Mienydd671972010-10-04 16:33:58 +0200333
Derek Allard2067d1a2008-11-13 22:59:24 +0000334 // --------------------------------------------------------------------
335
336 /**
337 * Affected Rows
338 *
Andrey Andreev1ff49e02012-01-27 11:30:41 +0200339 * @return int
Derek Allard2067d1a2008-11-13 22:59:24 +0000340 */
Andrey Andreev1ff49e02012-01-27 11:30:41 +0200341 public function affected_rows()
Derek Allard2067d1a2008-11-13 22:59:24 +0000342 {
Andrey Andreev992f1752012-03-19 16:58:43 +0200343 return $this->conn_id->affected_rows;
Derek Allard2067d1a2008-11-13 22:59:24 +0000344 }
Barry Mienydd671972010-10-04 16:33:58 +0200345
Derek Allard2067d1a2008-11-13 22:59:24 +0000346 // --------------------------------------------------------------------
347
348 /**
349 * Insert ID
350 *
Andrey Andreev1ff49e02012-01-27 11:30:41 +0200351 * @return int
Derek Allard2067d1a2008-11-13 22:59:24 +0000352 */
Andrey Andreev1ff49e02012-01-27 11:30:41 +0200353 public function insert_id()
Derek Allard2067d1a2008-11-13 22:59:24 +0000354 {
Andrey Andreev992f1752012-03-19 16:58:43 +0200355 return $this->conn_id->insert_id;
Derek Allard2067d1a2008-11-13 22:59:24 +0000356 }
357
358 // --------------------------------------------------------------------
359
360 /**
Derek Allard2067d1a2008-11-13 22:59:24 +0000361 * List table query
362 *
363 * Generates a platform-specific query string so that the table names can be fetched
364 *
Andrey Andreeva24e52e2012-11-02 03:54:12 +0200365 * @param bool $prefix_limit
Derek Allard2067d1a2008-11-13 22:59:24 +0000366 * @return string
367 */
Andrey Andreev1ff49e02012-01-27 11:30:41 +0200368 protected function _list_tables($prefix_limit = FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000369 {
Andrey Andreev473130a2012-06-24 02:51:18 +0300370 $sql = 'SHOW TABLES FROM '.$this->escape_identifiers($this->database);
Barry Mienydd671972010-10-04 16:33:58 +0200371
Alex Bilbie48a2baf2012-06-02 11:09:54 +0100372 if ($prefix_limit !== FALSE && $this->dbprefix !== '')
Derek Allard2067d1a2008-11-13 22:59:24 +0000373 {
Andrey Andreev1ff49e02012-01-27 11:30:41 +0200374 return $sql." LIKE '".$this->escape_like_str($this->dbprefix)."%'";
Derek Allard2067d1a2008-11-13 22:59:24 +0000375 }
Barry Mienydd671972010-10-04 16:33:58 +0200376
Derek Allard2067d1a2008-11-13 22:59:24 +0000377 return $sql;
378 }
379
380 // --------------------------------------------------------------------
381
382 /**
383 * Show column query
384 *
385 * Generates a platform-specific query string so that the column names can be fetched
386 *
Andrey Andreeva24e52e2012-11-02 03:54:12 +0200387 * @param string $table
Derek Allard2067d1a2008-11-13 22:59:24 +0000388 * @return string
389 */
Andrey Andreev1ff49e02012-01-27 11:30:41 +0200390 protected function _list_columns($table = '')
Derek Allard2067d1a2008-11-13 22:59:24 +0000391 {
Andrey Andreev032e7ea2012-03-06 19:48:35 +0200392 return 'SHOW COLUMNS FROM '.$this->protect_identifiers($table, TRUE, NULL, FALSE);
Derek Allard2067d1a2008-11-13 22:59:24 +0000393 }
394
395 // --------------------------------------------------------------------
396
397 /**
Andrey Andreev3722e502012-03-03 15:04:38 +0200398 * Returns an object with field data
Derek Allard2067d1a2008-11-13 22:59:24 +0000399 *
Andrey Andreeva24e52e2012-11-02 03:54:12 +0200400 * @param string $table
Andrey Andreev10ecc842012-11-16 01:06:20 +0200401 * @return array
Derek Allard2067d1a2008-11-13 22:59:24 +0000402 */
Andrey Andreev5350f052015-01-12 12:33:37 +0200403 public function field_data($table)
Derek Allard2067d1a2008-11-13 22:59:24 +0000404 {
Andrey Andreev10ecc842012-11-16 01:06:20 +0200405 if (($query = $this->query('SHOW COLUMNS FROM '.$this->protect_identifiers($table, TRUE, NULL, FALSE))) === FALSE)
406 {
407 return FALSE;
408 }
Andrey Andreev3722e502012-03-03 15:04:38 +0200409 $query = $query->result_object();
410
411 $retval = array();
412 for ($i = 0, $c = count($query); $i < $c; $i++)
413 {
Andrey Andreev3722e502012-03-03 15:04:38 +0200414 $retval[$i] = new stdClass();
415 $retval[$i]->name = $query[$i]->Field;
Andrey Andreev10ecc842012-11-16 01:06:20 +0200416
417 sscanf($query[$i]->Type, '%[a-z](%d)',
418 $retval[$i]->type,
419 $retval[$i]->max_length
420 );
421
Andrey Andreev3722e502012-03-03 15:04:38 +0200422 $retval[$i]->default = $query[$i]->Default;
Andrey Andreev3722e502012-03-03 15:04:38 +0200423 $retval[$i]->primary_key = (int) ($query[$i]->Key === 'PRI');
424 }
425
426 return $retval;
Derek Allard2067d1a2008-11-13 22:59:24 +0000427 }
428
429 // --------------------------------------------------------------------
430
431 /**
Andrey Andreev4be5de12012-03-02 15:45:41 +0200432 * Error
Derek Allard2067d1a2008-11-13 22:59:24 +0000433 *
Andrey Andreev4be5de12012-03-02 15:45:41 +0200434 * Returns an array containing code and message of the last
Claudio Galdiolob993b4b2015-01-28 12:22:38 -0500435 * database error that has occurred.
Derek Allard2067d1a2008-11-13 22:59:24 +0000436 *
Andrey Andreev4be5de12012-03-02 15:45:41 +0200437 * @return array
Derek Allard2067d1a2008-11-13 22:59:24 +0000438 */
Andrey Andreev4be5de12012-03-02 15:45:41 +0200439 public function error()
Derek Allard2067d1a2008-11-13 22:59:24 +0000440 {
Andrey Andreevdbad54e2012-10-05 21:53:32 +0300441 if ( ! empty($this->conn_id->connect_errno))
442 {
443 return array(
444 'code' => $this->conn_id->connect_errno,
445 'message' => is_php('5.2.9') ? $this->conn_id->connect_error : mysqli_connect_error()
446 );
447 }
448
Andrey Andreev992f1752012-03-19 16:58:43 +0200449 return array('code' => $this->conn_id->errno, 'message' => $this->conn_id->error);
Derek Allard2067d1a2008-11-13 22:59:24 +0000450 }
Barry Mienydd671972010-10-04 16:33:58 +0200451
Derek Allard2067d1a2008-11-13 22:59:24 +0000452 // --------------------------------------------------------------------
453
454 /**
Andrey Andreev7eaa14f2012-10-09 11:34:01 +0300455 * FROM tables
456 *
457 * Groups tables in FROM clauses if needed, so there is no confusion
458 * about operator precedence.
459 *
460 * @return string
461 */
462 protected function _from_tables()
463 {
Andrey Andreevfce9abe2012-10-09 11:37:00 +0300464 if ( ! empty($this->qb_join) && count($this->qb_from) > 1)
Andrey Andreev7eaa14f2012-10-09 11:34:01 +0300465 {
466 return '('.implode(', ', $this->qb_from).')';
467 }
468
469 return implode(', ', $this->qb_from);
470 }
471
472 // --------------------------------------------------------------------
473
474 /**
Derek Allard2067d1a2008-11-13 22:59:24 +0000475 * Close DB Connection
476 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000477 * @return void
478 */
Andrey Andreev79922c02012-05-23 12:27:17 +0300479 protected function _close()
Derek Allard2067d1a2008-11-13 22:59:24 +0000480 {
Andrey Andreev992f1752012-03-19 16:58:43 +0200481 $this->conn_id->close();
Derek Allard2067d1a2008-11-13 22:59:24 +0000482 }
483
Derek Allard2067d1a2008-11-13 22:59:24 +0000484}