blob: b94642b3547825ad72a33cdbb2c0a26a1ad73c46 [file] [log] [blame]
Andrey Andreevc5536aa2012-11-01 17:33:58 +02001<?php
Derek Allard2067d1a2008-11-13 22:59:24 +00002/**
3 * CodeIgniter
4 *
Phil Sturgeon07c1ac82012-03-09 17:03:37 +00005 * An open source application development framework for PHP 5.2.4 or newer
Derek Allard2067d1a2008-11-13 22:59:24 +00006 *
Derek Jonesf4a4bd82011-10-20 12:18:42 -05007 * NOTICE OF LICENSE
Andrey Andreev2caf2892012-01-27 00:12:03 +02008 *
Derek Jonesf4a4bd82011-10-20 12:18:42 -05009 * Licensed under the Open Software License version 3.0
Andrey Andreev2caf2892012-01-27 00:12:03 +020010 *
Derek Jonesf4a4bd82011-10-20 12:18:42 -050011 * This source file is subject to the Open Software License (OSL 3.0) that is
12 * bundled with this package in the files license.txt / license.rst. It is
13 * also available through the world wide web at this URL:
14 * http://opensource.org/licenses/OSL-3.0
15 * If you did not receive a copy of the license and are unable to obtain it
16 * through the world wide web, please send an email to
17 * licensing@ellislab.com so we can send you a copy immediately.
18 *
Derek Allard2067d1a2008-11-13 22:59:24 +000019 * @package CodeIgniter
Derek Jonesf4a4bd82011-10-20 12:18:42 -050020 * @author EllisLab Dev Team
Andrey Andreev80500af2013-01-01 08:16:53 +020021 * @copyright Copyright (c) 2008 - 2013, EllisLab, Inc. (http://ellislab.com/)
Derek Jonesf4a4bd82011-10-20 12:18:42 -050022 * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
Derek Allard2067d1a2008-11-13 22:59:24 +000023 * @link http://codeigniter.com
24 * @since Version 1.0
25 * @filesource
26 */
Andrey Andreevc5536aa2012-11-01 17:33:58 +020027defined('BASEPATH') OR exit('No direct script access allowed');
Derek Allard2067d1a2008-11-13 22:59:24 +000028
Derek Allard2067d1a2008-11-13 22:59:24 +000029/**
30 * MySQL Database Adapter Class
31 *
32 * Note: _DB is an extender class that the app controller
Jamie Rumbelow7efad202012-02-19 12:37:00 +000033 * creates dynamically based on whether the query builder
Derek Allard2067d1a2008-11-13 22:59:24 +000034 * class is being used or not.
35 *
36 * @package CodeIgniter
37 * @subpackage Drivers
38 * @category Database
Derek Jonesf4a4bd82011-10-20 12:18:42 -050039 * @author EllisLab Dev Team
Derek Allard2067d1a2008-11-13 22:59:24 +000040 * @link http://codeigniter.com/user_guide/database/
41 */
42class CI_DB_mysql_driver extends CI_DB {
43
Andrey Andreeva24e52e2012-11-02 03:54:12 +020044 /**
45 * Database driver
46 *
47 * @var string
48 */
Andrey Andreev2caf2892012-01-27 00:12:03 +020049 public $dbdriver = 'mysql';
RH Beckercfdb2322011-10-03 17:28:32 -070050
Derek Allard2067d1a2008-11-13 22:59:24 +000051 /**
Andrey Andreeva24e52e2012-11-02 03:54:12 +020052 * Compression flag
53 *
54 * @var bool
55 */
56 public $compress = FALSE;
57
58 /**
59 * DELETE hack flag
60 *
Andrey Andreev2caf2892012-01-27 00:12:03 +020061 * Whether to use the MySQL "delete hack" which allows the number
62 * of affected rows to be shown. Uses a preg_replace when enabled,
63 * adding a bit more processing to all queries.
Andrey Andreeva24e52e2012-11-02 03:54:12 +020064 *
65 * @var bool
Barry Mienydd671972010-10-04 16:33:58 +020066 */
Andrey Andreev2caf2892012-01-27 00:12:03 +020067 public $delete_hack = TRUE;
68
Andrey Andreeva24e52e2012-11-02 03:54:12 +020069 // --------------------------------------------------------------------
70
Andrey Andreev473130a2012-06-24 02:51:18 +030071 /**
Andrey Andreeva24e52e2012-11-02 03:54:12 +020072 * Identifier escape character
Andrey Andreev473130a2012-06-24 02:51:18 +030073 *
Andrey Andreeva24e52e2012-11-02 03:54:12 +020074 * @var string
75 */
76 protected $_escape_char = '`';
77
78 // --------------------------------------------------------------------
79
80 /**
81 * Class constructor
82 *
83 * @param array $params
Andrey Andreev473130a2012-06-24 02:51:18 +030084 * @return void
85 */
Andrey Andreev2caf2892012-01-27 00:12:03 +020086 public function __construct($params)
Derek Allard2067d1a2008-11-13 22:59:24 +000087 {
Andrey Andreev2caf2892012-01-27 00:12:03 +020088 parent::__construct($params);
89
Andrey Andreeve4c30192012-06-04 15:08:24 +030090 if ( ! empty($this->port))
Derek Allard2067d1a2008-11-13 22:59:24 +000091 {
92 $this->hostname .= ':'.$this->port;
93 }
Andrey Andreev2caf2892012-01-27 00:12:03 +020094 }
Barry Mienydd671972010-10-04 16:33:58 +020095
Andrey Andreev473130a2012-06-24 02:51:18 +030096 // --------------------------------------------------------------------
97
Andrey Andreev2caf2892012-01-27 00:12:03 +020098 /**
99 * Non-persistent database connection
100 *
Andrey Andreeva24e52e2012-11-02 03:54:12 +0200101 * @param bool $persistent
Andrey Andreev2caf2892012-01-27 00:12:03 +0200102 * @return resource
103 */
Andrey Andreev2f8bf9b2012-10-12 20:37:52 +0300104 public function db_connect($persistent = FALSE)
Andrey Andreev2caf2892012-01-27 00:12:03 +0200105 {
Andrey Andreev2f8bf9b2012-10-12 20:37:52 +0300106 $client_flags = ($this->compress === FALSE) ? 0 : MYSQL_CLIENT_COMPRESS;
107
108 if ($this->encrypt === TRUE)
Michiel Vugteveen49f7b722012-08-20 18:52:21 +0200109 {
Andrey Andreev2f8bf9b2012-10-12 20:37:52 +0300110 $client_flags = $client_flags | MYSQL_CLIENT_SSL;
Michiel Vugteveen49f7b722012-08-20 18:52:21 +0200111 }
Andrey Andreev2f8bf9b2012-10-12 20:37:52 +0300112
Andrey Andreev1a001492013-01-24 11:32:29 +0200113 $this->conn_id = ($persistent === TRUE)
Andrey Andreev98ebf432012-10-12 20:44:03 +0300114 ? @mysql_pconnect($this->hostname, $this->username, $this->password, $client_flags)
115 : @mysql_connect($this->hostname, $this->username, $this->password, TRUE, $client_flags);
Andrey Andreev1a001492013-01-24 11:32:29 +0200116
117 // ----------------------------------------------------------------
118
119 // Select the DB... assuming a database name is specified in the config file
120 if ($this->database !== '' && ! $this->db_select())
121 {
122 log_message('error', 'Unable to select database: '.$this->database);
123
124 return ($this->db_debug === TRUE)
125 ? $this->display_error('db_unable_to_select', $this->database)
126 : FALSE;
127 }
128
129 return $this->conn_id;
Derek Allard2067d1a2008-11-13 22:59:24 +0000130 }
Barry Mienydd671972010-10-04 16:33:58 +0200131
Derek Allard2067d1a2008-11-13 22:59:24 +0000132 // --------------------------------------------------------------------
133
134 /**
135 * Persistent database connection
136 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000137 * @return resource
Barry Mienydd671972010-10-04 16:33:58 +0200138 */
Andrey Andreev2caf2892012-01-27 00:12:03 +0200139 public function db_pconnect()
Derek Allard2067d1a2008-11-13 22:59:24 +0000140 {
Andrey Andreev2f8bf9b2012-10-12 20:37:52 +0300141 return $this->db_connect(TRUE);
Derek Allard2067d1a2008-11-13 22:59:24 +0000142 }
Barry Mienydd671972010-10-04 16:33:58 +0200143
Derek Allard2067d1a2008-11-13 22:59:24 +0000144 // --------------------------------------------------------------------
145
146 /**
Derek Jones87cbafc2009-02-27 16:29:59 +0000147 * Reconnect
148 *
149 * Keep / reestablish the db connection if no queries have been
150 * sent for a length of time exceeding the server's idle timeout
151 *
Derek Jones87cbafc2009-02-27 16:29:59 +0000152 * @return void
153 */
Andrey Andreev2caf2892012-01-27 00:12:03 +0200154 public function reconnect()
Derek Jones87cbafc2009-02-27 16:29:59 +0000155 {
156 if (mysql_ping($this->conn_id) === FALSE)
157 {
158 $this->conn_id = FALSE;
159 }
160 }
161
162 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200163
Derek Jones87cbafc2009-02-27 16:29:59 +0000164 /**
Derek Allard2067d1a2008-11-13 22:59:24 +0000165 * Select the database
166 *
Andrey Andreeva24e52e2012-11-02 03:54:12 +0200167 * @param string $database
Andrey Andreev2caf2892012-01-27 00:12:03 +0200168 * @return bool
Barry Mienydd671972010-10-04 16:33:58 +0200169 */
Andrey Andreev11454e02012-02-22 16:05:47 +0200170 public function db_select($database = '')
Derek Allard2067d1a2008-11-13 22:59:24 +0000171 {
Andrey Andreev024ba2d2012-02-24 11:40:36 +0200172 if ($database === '')
173 {
174 $database = $this->database;
175 }
176
177 if (@mysql_select_db($database, $this->conn_id))
178 {
179 $this->database = $database;
180 return TRUE;
181 }
182
183 return FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +0000184 }
185
186 // --------------------------------------------------------------------
187
188 /**
189 * Set client character set
190 *
Andrey Andreeva24e52e2012-11-02 03:54:12 +0200191 * @param string $charset
Andrey Andreev2caf2892012-01-27 00:12:03 +0200192 * @return bool
Derek Allard2067d1a2008-11-13 22:59:24 +0000193 */
Andrey Andreev95bd1d12012-03-12 16:22:28 +0200194 protected function _db_set_charset($charset)
Derek Allard2067d1a2008-11-13 22:59:24 +0000195 {
Andrey Andreevb3442a12012-03-12 15:35:40 +0200196 return @mysql_set_charset($charset, $this->conn_id);
Derek Allard2067d1a2008-11-13 22:59:24 +0000197 }
198
199 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200200
Derek Allard2067d1a2008-11-13 22:59:24 +0000201 /**
Andrey Andreev08856b82012-03-03 03:19:28 +0200202 * Database version number
Derek Allard2067d1a2008-11-13 22:59:24 +0000203 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000204 * @return string
205 */
Andrey Andreev08856b82012-03-03 03:19:28 +0200206 public function version()
Derek Allard2067d1a2008-11-13 22:59:24 +0000207 {
Andrey Andreev2b730372012-11-05 17:01:11 +0200208 if (isset($this->data_cache['version']))
209 {
210 return $this->data_cache['version'];
211 }
212 elseif ( ! $this->conn_id)
213 {
214 $this->initialize();
215 }
216
217 if ( ! $this->conn_id OR ($version = @mysql_get_server_info($this->conn_id)) === FALSE)
218 {
219 return FALSE;
220 }
221
222 return $this->data_cache['version'] = $version;
Derek Allard2067d1a2008-11-13 22:59:24 +0000223 }
224
225 // --------------------------------------------------------------------
226
227 /**
228 * Execute the query
229 *
Andrey Andreeva24e52e2012-11-02 03:54:12 +0200230 * @param string $sql an SQL query
Andrey Andreev2caf2892012-01-27 00:12:03 +0200231 * @return mixed
Barry Mienydd671972010-10-04 16:33:58 +0200232 */
Andrey Andreev2caf2892012-01-27 00:12:03 +0200233 protected function _execute($sql)
Derek Allard2067d1a2008-11-13 22:59:24 +0000234 {
Andrey Andreev2caf2892012-01-27 00:12:03 +0200235 return @mysql_query($this->_prep_query($sql), $this->conn_id);
Derek Allard2067d1a2008-11-13 22:59:24 +0000236 }
Barry Mienydd671972010-10-04 16:33:58 +0200237
Derek Allard2067d1a2008-11-13 22:59:24 +0000238 // --------------------------------------------------------------------
239
240 /**
241 * Prep the query
242 *
243 * If needed, each database adapter can prep the query string
244 *
Andrey Andreeva24e52e2012-11-02 03:54:12 +0200245 * @param string $sql an SQL query
Derek Allard2067d1a2008-11-13 22:59:24 +0000246 * @return string
Barry Mienydd671972010-10-04 16:33:58 +0200247 */
Andrey Andreev2caf2892012-01-27 00:12:03 +0200248 protected function _prep_query($sql)
Derek Allard2067d1a2008-11-13 22:59:24 +0000249 {
Andrey Andreev2caf2892012-01-27 00:12:03 +0200250 // mysql_affected_rows() returns 0 for "DELETE FROM TABLE" queries. This hack
251 // modifies the query so that it a proper number of affected rows is returned.
252 if ($this->delete_hack === TRUE && preg_match('/^\s*DELETE\s+FROM\s+(\S+)\s*$/i', $sql))
Derek Allard2067d1a2008-11-13 22:59:24 +0000253 {
Andrey Andreevbe999662013-01-10 11:40:09 +0200254 return trim($sql).' WHERE 1=1';
Derek Allard2067d1a2008-11-13 22:59:24 +0000255 }
Barry Mienydd671972010-10-04 16:33:58 +0200256
Derek Allard2067d1a2008-11-13 22:59:24 +0000257 return $sql;
258 }
259
260 // --------------------------------------------------------------------
261
262 /**
263 * Begin Transaction
264 *
Andrey Andreeva24e52e2012-11-02 03:54:12 +0200265 * @param bool $test_mode
Barry Mienydd671972010-10-04 16:33:58 +0200266 * @return bool
267 */
Andrey Andreev2caf2892012-01-27 00:12:03 +0200268 public function trans_begin($test_mode = FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000269 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000270 // When transactions are nested we only begin/commit/rollback the outermost ones
Andrey Andreev2caf2892012-01-27 00:12:03 +0200271 if ( ! $this->trans_enabled OR $this->_trans_depth > 0)
Derek Allard2067d1a2008-11-13 22:59:24 +0000272 {
273 return TRUE;
274 }
275
276 // Reset the transaction failure flag.
277 // If the $test_mode flag is set to TRUE transactions will be rolled back
278 // even if the queries produce a successful result.
Andrey Andreev2caf2892012-01-27 00:12:03 +0200279 $this->_trans_failure = ($test_mode === TRUE);
Barry Mienydd671972010-10-04 16:33:58 +0200280
Derek Allard2067d1a2008-11-13 22:59:24 +0000281 $this->simple_query('SET AUTOCOMMIT=0');
282 $this->simple_query('START TRANSACTION'); // can also be BEGIN or BEGIN WORK
283 return TRUE;
284 }
285
286 // --------------------------------------------------------------------
287
288 /**
289 * Commit Transaction
290 *
Barry Mienydd671972010-10-04 16:33:58 +0200291 * @return bool
292 */
Andrey Andreev2caf2892012-01-27 00:12:03 +0200293 public function trans_commit()
Derek Allard2067d1a2008-11-13 22:59:24 +0000294 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000295 // When transactions are nested we only begin/commit/rollback the outermost ones
Andrey Andreev2caf2892012-01-27 00:12:03 +0200296 if ( ! $this->trans_enabled OR $this->_trans_depth > 0)
Derek Allard2067d1a2008-11-13 22:59:24 +0000297 {
298 return TRUE;
299 }
300
301 $this->simple_query('COMMIT');
302 $this->simple_query('SET AUTOCOMMIT=1');
303 return TRUE;
304 }
305
306 // --------------------------------------------------------------------
307
308 /**
309 * Rollback Transaction
310 *
Barry Mienydd671972010-10-04 16:33:58 +0200311 * @return bool
312 */
Andrey Andreev2caf2892012-01-27 00:12:03 +0200313 public function trans_rollback()
Derek Allard2067d1a2008-11-13 22:59:24 +0000314 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000315 // When transactions are nested we only begin/commit/rollback the outermost ones
Andrey Andreev2caf2892012-01-27 00:12:03 +0200316 if ( ! $this->trans_enabled OR $this->_trans_depth > 0)
Derek Allard2067d1a2008-11-13 22:59:24 +0000317 {
318 return TRUE;
319 }
320
321 $this->simple_query('ROLLBACK');
322 $this->simple_query('SET AUTOCOMMIT=1');
323 return TRUE;
324 }
Barry Mienydd671972010-10-04 16:33:58 +0200325
Derek Allard2067d1a2008-11-13 22:59:24 +0000326 // --------------------------------------------------------------------
327
328 /**
Andrey Andreev0b6a4922013-01-10 16:53:44 +0200329 * Platform-dependant string escape
Derek Allard2067d1a2008-11-13 22:59:24 +0000330 *
Andrey Andreev0b6a4922013-01-10 16:53:44 +0200331 * @param string
Derek Allard2067d1a2008-11-13 22:59:24 +0000332 * @return string
333 */
Andrey Andreev0b6a4922013-01-10 16:53:44 +0200334 protected function _escape_str($str)
Barry Mienydd671972010-10-04 16:33:58 +0200335 {
Andrey Andreev0b6a4922013-01-10 16:53:44 +0200336 return is_resource($this->conn_id)
337 ? mysql_real_escape_string($str, $this->conn_id)
338 : addslashes($str);
Derek Allard2067d1a2008-11-13 22:59:24 +0000339 }
Barry Mienydd671972010-10-04 16:33:58 +0200340
Derek Allard2067d1a2008-11-13 22:59:24 +0000341 // --------------------------------------------------------------------
342
343 /**
344 * Affected Rows
345 *
Andrey Andreev2caf2892012-01-27 00:12:03 +0200346 * @return int
Derek Allard2067d1a2008-11-13 22:59:24 +0000347 */
Andrey Andreev2caf2892012-01-27 00:12:03 +0200348 public function affected_rows()
Derek Allard2067d1a2008-11-13 22:59:24 +0000349 {
350 return @mysql_affected_rows($this->conn_id);
351 }
Barry Mienydd671972010-10-04 16:33:58 +0200352
Derek Allard2067d1a2008-11-13 22:59:24 +0000353 // --------------------------------------------------------------------
354
355 /**
356 * Insert ID
357 *
Andrey Andreev2caf2892012-01-27 00:12:03 +0200358 * @return int
Derek Allard2067d1a2008-11-13 22:59:24 +0000359 */
Andrey Andreev2caf2892012-01-27 00:12:03 +0200360 public function insert_id()
Derek Allard2067d1a2008-11-13 22:59:24 +0000361 {
362 return @mysql_insert_id($this->conn_id);
363 }
364
365 // --------------------------------------------------------------------
366
367 /**
Derek Allard2067d1a2008-11-13 22:59:24 +0000368 * List table query
369 *
370 * Generates a platform-specific query string so that the table names can be fetched
371 *
Andrey Andreeva24e52e2012-11-02 03:54:12 +0200372 * @param bool $prefix_limit
Derek Allard2067d1a2008-11-13 22:59:24 +0000373 * @return string
374 */
Andrey Andreev2caf2892012-01-27 00:12:03 +0200375 protected function _list_tables($prefix_limit = FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000376 {
Andrey Andreev473130a2012-06-24 02:51:18 +0300377 $sql = 'SHOW TABLES FROM '.$this->escape_identifiers($this->database);
Derek Allard2067d1a2008-11-13 22:59:24 +0000378
Alex Bilbie48a2baf2012-06-02 11:09:54 +0100379 if ($prefix_limit !== FALSE && $this->dbprefix !== '')
Derek Allard2067d1a2008-11-13 22:59:24 +0000380 {
Andrey Andreev2caf2892012-01-27 00:12:03 +0200381 return $sql." LIKE '".$this->escape_like_str($this->dbprefix)."%'";
Derek Allard2067d1a2008-11-13 22:59:24 +0000382 }
383
384 return $sql;
385 }
Barry Mienydd671972010-10-04 16:33:58 +0200386
Derek Allard2067d1a2008-11-13 22:59:24 +0000387 // --------------------------------------------------------------------
388
389 /**
390 * Show column query
391 *
392 * Generates a platform-specific query string so that the column names can be fetched
393 *
Andrey Andreeva24e52e2012-11-02 03:54:12 +0200394 * @param string $table
Derek Allard2067d1a2008-11-13 22:59:24 +0000395 * @return string
396 */
Andrey Andreev473130a2012-06-24 02:51:18 +0300397 protected function _list_columns($table = '')
Derek Allard2067d1a2008-11-13 22:59:24 +0000398 {
Andrey Andreev2caf2892012-01-27 00:12:03 +0200399 return 'SHOW COLUMNS FROM '.$this->protect_identifiers($table, TRUE, NULL, FALSE);
Derek Allard2067d1a2008-11-13 22:59:24 +0000400 }
401
402 // --------------------------------------------------------------------
403
404 /**
Andrey Andreev3722e502012-03-03 15:04:38 +0200405 * Returns an object with field data
Derek Allard2067d1a2008-11-13 22:59:24 +0000406 *
Andrey Andreeva24e52e2012-11-02 03:54:12 +0200407 * @param string $table
Andrey Andreev10ecc842012-11-16 01:06:20 +0200408 * @return array
Derek Allard2067d1a2008-11-13 22:59:24 +0000409 */
Andrey Andreev3722e502012-03-03 15:04:38 +0200410 public function field_data($table = '')
Derek Allard2067d1a2008-11-13 22:59:24 +0000411 {
Alex Bilbie48a2baf2012-06-02 11:09:54 +0100412 if ($table === '')
Andrey Andreev3722e502012-03-03 15:04:38 +0200413 {
414 return ($this->db_debug) ? $this->display_error('db_field_param_missing') : FALSE;
415 }
416
Andrey Andreev10ecc842012-11-16 01:06:20 +0200417 if (($query = $this->query('SHOW COLUMNS FROM '.$this->protect_identifiers($table, TRUE, NULL, FALSE))) === FALSE)
418 {
419 return FALSE;
420 }
Andrey Andreev3722e502012-03-03 15:04:38 +0200421 $query = $query->result_object();
422
423 $retval = array();
424 for ($i = 0, $c = count($query); $i < $c; $i++)
425 {
Andrey Andreev3722e502012-03-03 15:04:38 +0200426 $retval[$i] = new stdClass();
427 $retval[$i]->name = $query[$i]->Field;
Andrey Andreev10ecc842012-11-16 01:06:20 +0200428
429 sscanf($query[$i]->Type, '%[a-z](%d)',
430 $retval[$i]->type,
431 $retval[$i]->max_length
432 );
433
Andrey Andreev3722e502012-03-03 15:04:38 +0200434 $retval[$i]->default = $query[$i]->Default;
Andrey Andreev3722e502012-03-03 15:04:38 +0200435 $retval[$i]->primary_key = (int) ($query[$i]->Key === 'PRI');
436 }
437
438 return $retval;
Derek Allard2067d1a2008-11-13 22:59:24 +0000439 }
440
441 // --------------------------------------------------------------------
442
443 /**
Andrey Andreev4be5de12012-03-02 15:45:41 +0200444 * Error
Derek Allard2067d1a2008-11-13 22:59:24 +0000445 *
Andrey Andreev4be5de12012-03-02 15:45:41 +0200446 * Returns an array containing code and message of the last
447 * database error that has occured.
Derek Allard2067d1a2008-11-13 22:59:24 +0000448 *
Andrey Andreev4be5de12012-03-02 15:45:41 +0200449 * @return array
Derek Allard2067d1a2008-11-13 22:59:24 +0000450 */
Andrey Andreev4be5de12012-03-02 15:45:41 +0200451 public function error()
Derek Allard2067d1a2008-11-13 22:59:24 +0000452 {
Andrey Andreev4be5de12012-03-02 15:45:41 +0200453 return array('code' => mysql_errno($this->conn_id), 'message' => mysql_error($this->conn_id));
Derek Allard2067d1a2008-11-13 22:59:24 +0000454 }
455
456 // --------------------------------------------------------------------
457
458 /**
Andrey Andreev7eaa14f2012-10-09 11:34:01 +0300459 * FROM tables
460 *
461 * Groups tables in FROM clauses if needed, so there is no confusion
462 * about operator precedence.
463 *
464 * @return string
465 */
466 protected function _from_tables()
467 {
Andrey Andreevfce9abe2012-10-09 11:37:00 +0300468 if ( ! empty($this->qb_join) && count($this->qb_from) > 1)
Andrey Andreev7eaa14f2012-10-09 11:34:01 +0300469 {
470 return '('.implode(', ', $this->qb_from).')';
471 }
472
473 return implode(', ', $this->qb_from);
474 }
475
476 // --------------------------------------------------------------------
477
478 /**
Derek Allard2067d1a2008-11-13 22:59:24 +0000479 * Close DB Connection
480 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000481 * @return void
482 */
Andrey Andreev79922c02012-05-23 12:27:17 +0300483 protected function _close()
Derek Allard2067d1a2008-11-13 22:59:24 +0000484 {
Andrey Andreev79922c02012-05-23 12:27:17 +0300485 @mysql_close($this->conn_id);
Derek Allard2067d1a2008-11-13 22:59:24 +0000486 }
Barry Mienydd671972010-10-04 16:33:58 +0200487
Derek Allard2067d1a2008-11-13 22:59:24 +0000488}
489
Derek Allard2067d1a2008-11-13 22:59:24 +0000490/* End of file mysql_driver.php */
Andrey Andreev79922c02012-05-23 12:27:17 +0300491/* Location: ./system/database/drivers/mysql/mysql_driver.php */