blob: 73c723d9620cd6d5bd534dc71ff3ed3735eb698f [file] [log] [blame]
admin7b613c72006-09-24 18:05:17 +00001<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
2/**
3 * Code Igniter
4 *
5 * An open source application development framework for PHP 4.3.2 or newer
6 *
7 * @package CodeIgniter
8 * @author Rick Ellis
9 * @copyright Copyright (c) 2006, pMachine, Inc.
10 * @license http://www.codeignitor.com/user_guide/license.html
11 * @link http://www.codeigniter.com
12 * @since Version 1.0
13 * @filesource
14 */
15
16// ------------------------------------------------------------------------
17
18/**
19 * Database Driver Class
20 *
21 * This is the platform-independent base DB implementation class.
22 * This class will not be called directly. Rather, the adapter
23 * class for the specific database will extend and instantiate it.
24 *
25 * @package CodeIgniter
26 * @subpackage Drivers
27 * @category Database
28 * @author Rick Ellis
29 * @link http://www.codeigniter.com/user_guide/database/
30 */
31class CI_DB_driver {
32
33 var $username;
34 var $password;
35 var $hostname;
36 var $database;
37 var $dbdriver = 'mysql';
38 var $dbprefix = '';
39 var $port = '';
40 var $pconnect = FALSE;
41 var $conn_id = FALSE;
42 var $result_id = FALSE;
43 var $db_debug = FALSE;
admine8f6eb62006-10-02 06:46:16 +000044 var $query_caching = FALSE;
45 var $cache_dir = '';
admin7b613c72006-09-24 18:05:17 +000046 var $benchmark = 0;
47 var $query_count = 0;
48 var $bind_marker = '?';
49 var $queries = array();
admine8f6eb62006-10-02 06:46:16 +000050 var $data_cache = array();
admin7b613c72006-09-24 18:05:17 +000051 var $trans_enabled = TRUE;
52 var $_trans_depth = 0;
53 var $_trans_failure = FALSE; // Used with transactions to determine if a rollback should occur
54
55 // These are use with Oracle
56 var $stmt_id;
57 var $curs_id;
58 var $limit_used;
59
admine8f6eb62006-10-02 06:46:16 +000060
admin7b613c72006-09-24 18:05:17 +000061
62 /**
63 * Constructor. Accepts one parameter containing the database
64 * connection settings.
65 *
66 * Database settings can be passed as discreet
67 * parameters or as a data source name in the first
68 * parameter. DSNs must have this prototype:
69 * $dsn = 'driver://username:password@hostname/database';
70 *
71 * @param mixed. Can be an array or a DSN string
72 */
73 function CI_DB_driver($params)
74 {
75 $this->initialize($params);
76 log_message('debug', 'Database Driver Class Initialized');
77 }
78
79 // --------------------------------------------------------------------
80
81 /**
82 * Initialize Database Settings
83 *
84 * @access private Called by the constructor
85 * @param mixed
86 * @return void
87 */
88 function initialize($params = '')
89 {
90 if (is_array($params))
91 {
92 foreach (array('hostname' => '', 'username' => '', 'password' => '', 'database' => '', 'dbdriver' => 'mysql', 'dbprefix' => '', 'port' => '', 'pconnect' => FALSE, 'db_debug' => FALSE) as $key => $val)
93 {
94 $this->$key = ( ! isset($params[$key])) ? $val : $params[$key];
95 }
96 }
97 elseif (strpos($params, '://'))
98 {
99 if (FALSE === ($dsn = @parse_url($params)))
100 {
101 log_message('error', 'Invalid DB Connection String');
102
103 if ($this->db_debug)
104 {
105 return $this->display_error('db_invalid_connection_str');
106 }
107 return FALSE;
108 }
109
110 $this->hostname = ( ! isset($dsn['host'])) ? '' : rawurldecode($dsn['host']);
111 $this->username = ( ! isset($dsn['user'])) ? '' : rawurldecode($dsn['user']);
112 $this->password = ( ! isset($dsn['pass'])) ? '' : rawurldecode($dsn['pass']);
113 $this->database = ( ! isset($dsn['path'])) ? '' : rawurldecode(substr($dsn['path'], 1));
114 }
115
116 if ($this->pconnect == FALSE)
117 {
118 $this->conn_id = $this->db_connect();
119 }
120 else
121 {
122 $this->conn_id = $this->db_pconnect();
123 }
124
125 if ( ! $this->conn_id)
126 {
127 log_message('error', 'Unable to connect to the database');
128
129 if ($this->db_debug)
130 {
131 $this->display_error('db_unable_to_connect');
132 }
133 }
134 else
135 {
136 if ( ! $this->db_select())
137 {
138 log_message('error', 'Unable to select database: '.$this->database);
139
140 if ($this->db_debug)
141 {
142 $this->display_error('db_unable_to_select', $this->database);
143 }
144 }
145 }
146 }
147
148
149 // --------------------------------------------------------------------
150
151 /**
admin9cd4e8e2006-09-25 23:26:25 +0000152 * The name of the platform in use (mysql, mssql, etc...)
153 *
154 * @access public
155 * @return string
156 */
157 function platform()
158 {
159 return $this->dbdriver;
160 }
161
162 // --------------------------------------------------------------------
163
164 /**
165 * Database Version Number. Returns a string containing the
166 * version of the database being used
167 *
168 * @access public
169 * @return string
170 */
171 function version()
172 {
173 if (FALSE === ($sql = $this->_version()))
174 {
175 if ($this->db_debug)
176 {
177 return $this->display_error('db_unsupported_function');
178 }
179 return FALSE;
180 }
181
182 if ($this->dbdriver == 'oci8')
183 {
184 return $sql;
185 }
186
187 $query = $this->query($sql);
188 $row = $query->row();
189 return $row->ver;
190 }
191
192 // --------------------------------------------------------------------
193
194 /**
admin7b613c72006-09-24 18:05:17 +0000195 * Execute the query
196 *
197 * Accepts an SQL string as input and returns a result object upon
198 * successful execution of a "read" type query. Returns boolean TRUE
199 * upon successful execution of a "write" type query. Returns boolean
200 * FALSE upon failure, and if the $db_debug variable is set to TRUE
201 * will raise an error.
202 *
203 * @access public
204 * @param string An SQL query string
205 * @param array An array of binding data
206 * @return mixed
207 */
208 function query($sql, $binds = FALSE, $return_object = TRUE)
209 {
210 if ($sql == '')
211 {
212 if ($this->db_debug)
213 {
214 log_message('error', 'Invalid query: '.$sql);
215 return $this->display_error('db_invalid_query');
216 }
217 return FALSE;
218 }
219
admine8f6eb62006-10-02 06:46:16 +0000220 // Is query caching enabled? If the query is a "read type" we'll
221 // grab the previously cached query if it exists and return it.
222 if ($this->query_caching == TRUE)
223 {
224 if (stristr($sql, 'SELECT'))
225 {
226 $CACHE =& _load_cache_class();
227
228 if (FALSE !== ($CACHE->cache_exists($sql)))
229 {
230 return $CACHE->get_cache($sql);
231 }
232 }
233 }
234
admin7b613c72006-09-24 18:05:17 +0000235 // Compile binds if needed
236 if ($binds !== FALSE)
237 {
238 $sql = $this->compile_binds($sql, $binds);
239 }
240
241 // Save the query for debugging
242 $this->queries[] = $sql;
243
244 // Start the Query Timer
245 $time_start = list($sm, $ss) = explode(' ', microtime());
246
247 // Run the Query
248 if (FALSE === ($this->result_id = $this->simple_query($sql)))
249 {
250 // This will trigger a rollback if transactions are being used
251 $this->_trans_failure = TRUE;
252
253 if ($this->db_debug)
254 {
adminbb1d4392006-09-24 20:14:38 +0000255 log_message('error', 'Query error: '.$this->_error_message());
admin7b613c72006-09-24 18:05:17 +0000256 return $this->display_error(
257 array(
adminbb1d4392006-09-24 20:14:38 +0000258 'Error Number: '.$this->_error_number(),
259 $this->_error_message(),
admin7b613c72006-09-24 18:05:17 +0000260 $sql
261 )
262 );
263 }
264
265 return FALSE;
266 }
267
268 // Stop and aggregate the query time results
269 $time_end = list($em, $es) = explode(' ', microtime());
270 $this->benchmark += ($em + $es) - ($sm + $ss);
271
272 // Increment the query counter
273 $this->query_count++;
274
275 // Was the query a "write" type?
276 // If so we'll simply return true
277 if ($this->is_write_type($sql) === TRUE)
admine8f6eb62006-10-02 06:46:16 +0000278 {
admin7b613c72006-09-24 18:05:17 +0000279 return TRUE;
280 }
281
282 // Return TRUE if we don't need to create a result object
283 // Currently only the Oracle driver uses this when stored
284 // procedures are used
285 if ($return_object !== TRUE)
286 {
287 return TRUE;
288 }
289
290 // Define the result driver name
291 $result = 'CI_DB_'.$this->dbdriver.'_result';
292
293 // Load the result classes
294 if ( ! class_exists($result))
295 {
296 include_once(BASEPATH.'database/DB_result'.EXT);
297 include_once(BASEPATH.'database/drivers/'.$this->dbdriver.'/'.$this->dbdriver.'_result'.EXT);
298 }
299
300 // Instantiate the result object
301 $RES = new $result();
302 $RES->conn_id = $this->conn_id;
303 $RES->db_debug = $this->db_debug;
304 $RES->result_id = $this->result_id;
305
306 if ($this->dbdriver == 'oci8')
307 {
308 $RES->stmt_id = $this->stmt_id;
309 $RES->curs_id = NULL;
310 $RES->limit_used = $this->limit_used;
311 }
312
313 return $RES;
314 }
315
316 // --------------------------------------------------------------------
317
318 /**
319 * Simple Query
320 * This is a simiplified version of the query() function. Internally
321 * we only use it when running transaction commands since they do
322 * not require all the features of the main query() function.
323 *
324 * @access public
325 * @param string the sql query
326 * @return mixed
327 */
328 function simple_query($sql)
329 {
330 if ( ! $this->conn_id)
331 {
332 $this->initialize();
333 }
334
335 return $this->_execute($sql, $this->conn_id);
336 }
337
338 // --------------------------------------------------------------------
339
340 /**
341 * Disable Transactions
342 * This permits transactions to be disabled at run-time.
343 *
344 * @access public
345 * @return void
346 */
347 function trans_off()
348 {
349 $this->trans_enabled = FALSE;
350 }
351
352 // --------------------------------------------------------------------
353
354 /**
355 * Start Transaction
356 *
357 * @access public
358 * @return void
359 */
360 function trans_start($test_mode = FALSE)
361 {
362 if ( ! $this->trans_enabled)
363 {
364 return FALSE;
365 }
366
367 // When transactions are nested we only begin/commit/rollback the outermost ones
368 if ($this->_trans_depth > 0)
369 {
370 $this->_trans_depth += 1;
371 return;
372 }
373
374 $this->trans_begin($test_mode);
375 }
376
377 // --------------------------------------------------------------------
378
379 /**
380 * Complete Transaction
381 *
382 * @access public
383 * @return bool
384 */
385 function trans_complete()
386 {
387 if ( ! $this->trans_enabled)
388 {
389 return FALSE;
390 }
391
392 // When transactions are nested we only begin/commit/rollback the outermost ones
393 if ($this->_trans_depth > 1)
394 {
395 $this->_trans_depth -= 1;
396 return TRUE;
397 }
398
399 // The query() function will set this flag to TRUE in the event that a query failed
400 if ($this->_trans_failure === TRUE)
401 {
402 $this->trans_rollback();
403
404 if ($this->db_debug)
405 {
406 return $this->display_error('db_transaction_failure');
407 }
408 return FALSE;
409 }
410
411 $this->trans_commit();
412 return TRUE;
413 }
414
415 // --------------------------------------------------------------------
416
417 /**
418 * Lets you retrieve the transaction flag to determine if it has failed
419 *
420 * @access public
421 * @return bool
422 */
423 function trans_status()
424 {
425 return $this->_trans_failure;
426 }
427
428 // --------------------------------------------------------------------
429
430 /**
431 * Compile Bindings
432 *
433 * @access public
434 * @param string the sql statement
435 * @param array an array of bind data
436 * @return string
437 */
438 function compile_binds($sql, $binds)
439 {
440 if (FALSE === strpos($sql, $this->bind_marker))
441 {
442 return $sql;
443 }
444
445 if ( ! is_array($binds))
446 {
447 $binds = array($binds);
448 }
449
450 foreach ($binds as $val)
451 {
452 $val = $this->escape($val);
453
454 // Just in case the replacement string contains the bind
455 // character we'll temporarily replace it with a marker
456 $val = str_replace($this->bind_marker, '{%bind_marker%}', $val);
457 $sql = preg_replace("#".preg_quote($this->bind_marker, '#')."#", str_replace('$', '\$', $val), $sql, 1);
458 }
459
460 return str_replace('{%bind_marker%}', $this->bind_marker, $sql);
461 }
462
463 // --------------------------------------------------------------------
464
465 /**
466 * Determines if a query is a "write" type.
467 *
468 * @access public
469 * @param string An SQL query string
470 * @return boolean
471 */
472 function is_write_type($sql)
473 {
474 if ( ! preg_match('/^\s*"?(INSERT|UPDATE|DELETE|REPLACE|CREATE|DROP|LOAD DATA|COPY|ALTER|GRANT|REVOKE|LOCK|UNLOCK)\s+/i', $sql))
475 {
476 return FALSE;
477 }
478 return TRUE;
479 }
480
481 // --------------------------------------------------------------------
482
483 /**
484 * Calculate the aggregate query elapsed time
485 *
486 * @access public
487 * @param intiger The number of decimal places
488 * @return integer
489 */
490 function elapsed_time($decimals = 6)
491 {
492 return number_format($this->benchmark, $decimals);
493 }
494
495 // --------------------------------------------------------------------
496
497 /**
498 * Returns the total number of queries
499 *
500 * @access public
501 * @return integer
502 */
503 function total_queries()
504 {
505 return $this->query_count;
506 }
507
508 // --------------------------------------------------------------------
509
510 /**
511 * Returns the last query that was executed
512 *
513 * @access public
514 * @return void
515 */
516 function last_query()
517 {
518 return end($this->queries);
519 }
520
521 // --------------------------------------------------------------------
522
523 /**
524 * "Smart" Escape String
525 *
526 * Escapes data based on type
527 * Sets boolean and null types
528 *
529 * @access public
530 * @param string
531 * @return integer
532 */
533 function escape($str)
534 {
535 switch (gettype($str))
536 {
537 case 'string' : $str = "'".$this->escape_str($str)."'";
538 break;
539 case 'boolean' : $str = ($str === FALSE) ? 0 : 1;
540 break;
541 default : $str = ($str === NULL) ? 'NULL' : $str;
542 break;
543 }
544
545 return $str;
adminbb1d4392006-09-24 20:14:38 +0000546 }
547
admin9cd4e8e2006-09-25 23:26:25 +0000548
549
550 // --------------------------------------------------------------------
551
552 /**
553 * Primary
554 *
555 * Retrieves the primary key. It assumes that the row in the first
556 * position is the primary key
557 *
558 * @access public
559 * @param string the table name
560 * @return string
561 */
562 function primary($table = '')
563 {
564 $fields = $this->field_names($table);
565
566 if ( ! is_array($fields))
567 {
568 return FALSE;
569 }
570
571 return current($fields);
572 }
573
574 // --------------------------------------------------------------------
575
admin3dd978f2006-09-30 19:24:45 +0000576 /**
577 * Returns an array of table names
578 *
579 * @access public
580 * @return array
581 */
582 function list_tables()
583 {
584 // Is there a cached result?
admine8f6eb62006-10-02 06:46:16 +0000585 if (isset($this->data_cache['table_names']))
admin3dd978f2006-09-30 19:24:45 +0000586 {
admine8f6eb62006-10-02 06:46:16 +0000587 return $this->data_cache['table_names'];
admin3dd978f2006-09-30 19:24:45 +0000588 }
589
590 if (FALSE === ($sql = $this->_list_tables()))
591 {
592 if ($this->db_debug)
593 {
594 return $this->display_error('db_unsupported_function');
595 }
596 return FALSE;
597 }
598
599 $retval = array();
600 $query = $this->query($sql);
601
602 if ($query->num_rows() > 0)
603 {
604 foreach($query->result_array() as $row)
605 {
606 if (isset($row['TABLE_NAME']))
607 {
608 $retval[] = $row['TABLE_NAME'];
609 }
610 else
611 {
612 $retval[] = array_shift($row);
613 }
614 }
615 }
616
admine8f6eb62006-10-02 06:46:16 +0000617 return $this->data_cache['table_names'] =& $retval;
admin3dd978f2006-09-30 19:24:45 +0000618 }
619
620 // --------------------------------------------------------------------
621
622 /**
623 * Determine if a particular table exists
624 * @access public
625 * @return boolean
626 */
627 function table_exists($table_name)
628 {
629 return ( ! in_array($this->dbprefix.$table_name, $this->list_tables())) ? FALSE : TRUE;
630 }
631
632 // --------------------------------------------------------------------
633
admin9cd4e8e2006-09-25 23:26:25 +0000634 /**
635 * Fetch MySQL Field Names
636 *
637 * @access public
638 * @param string the table name
639 * @return array
640 */
admin3dd978f2006-09-30 19:24:45 +0000641 function list_fields($table = '')
admin9cd4e8e2006-09-25 23:26:25 +0000642 {
admin3ed8c512006-09-29 23:26:28 +0000643 // Is there a cached result?
admine8f6eb62006-10-02 06:46:16 +0000644 if (isset($this->data_cache['field_names'][$table]))
admin3ed8c512006-09-29 23:26:28 +0000645 {
admine8f6eb62006-10-02 06:46:16 +0000646 return $this->data_cache['field_names'][$table];
admin3ed8c512006-09-29 23:26:28 +0000647 }
648
admin9cd4e8e2006-09-25 23:26:25 +0000649 if ($table == '')
650 {
651 if ($this->db_debug)
652 {
653 return $this->display_error('db_field_param_missing');
654 }
655 return FALSE;
656 }
657
658 if (FALSE === ($sql = $this->_list_columns($this->dbprefix.$table)))
659 {
660 if ($this->db_debug)
661 {
662 return $this->display_error('db_unsupported_function');
663 }
664 return FALSE;
665 }
666
667 $query = $this->query($sql);
668
669 $retval = array();
670 foreach($query->result_array() as $row)
671 {
672 if (isset($row['COLUMN_NAME']))
673 {
674 $retval[] = $row['COLUMN_NAME'];
675 }
676 else
677 {
678 $retval[] = current($row);
679 }
680 }
681
admine8f6eb62006-10-02 06:46:16 +0000682 return $this->data_cache['field_names'][$table] =& $retval;
admin9cd4e8e2006-09-25 23:26:25 +0000683 }
adminb2a9cec2006-10-01 03:38:04 +0000684
685 // --------------------------------------------------------------------
686
687 /**
688 * Determine if a particular field exists
689 * @access public
690 * @param string
691 * @param string
692 * @return boolean
693 */
694 function field_exists($field_name, $table_name)
695 {
696 return ( ! in_array($field_name, $this->list_fields($table_name))) ? FALSE : TRUE;
697 }
admin3dd978f2006-09-30 19:24:45 +0000698
699 // --------------------------------------------------------------------
700
701 /**
702 * DEPRECATED - use list_fields()
703 */
704 function field_names($table = '')
705 {
706 return $this->list_fields($table);
707 }
admin9cd4e8e2006-09-25 23:26:25 +0000708
709 // --------------------------------------------------------------------
710
711 /**
712 * Returns an object with field data
713 *
714 * @access public
715 * @param string the table name
716 * @return object
717 */
718 function field_data($table = '')
719 {
720 if ($table == '')
721 {
722 if ($this->db_debug)
723 {
724 return $this->display_error('db_field_param_missing');
725 }
726 return FALSE;
727 }
728
729 $query = $this->query($this->_field_data($this->dbprefix.$table));
730 return $query->field_data();
731 }
732
adminbb1d4392006-09-24 20:14:38 +0000733 // --------------------------------------------------------------------
734
735 /**
736 * Generate an insert string
737 *
738 * @access public
739 * @param string the table upon which the query will be performed
740 * @param array an associative array data of key/values
741 * @return string
742 */
743 function insert_string($table, $data)
744 {
745 $fields = array();
746 $values = array();
747
748 foreach($data as $key => $val)
749 {
750 $fields[] = $key;
751 $values[] = $this->escape($val);
752 }
753
754 return $this->_insert($this->dbprefix.$table, $fields, $values);
755 }
756
757 // --------------------------------------------------------------------
758
759 /**
760 * Generate an update string
761 *
762 * @access public
763 * @param string the table upon which the query will be performed
764 * @param array an associative array data of key/values
765 * @param mixed the "where" statement
766 * @return string
767 */
768 function update_string($table, $data, $where)
769 {
770 if ($where == '')
771 return false;
772
773 $fields = array();
774 foreach($data as $key => $val)
775 {
776 $fields[$key] = $this->escape($val);
777 }
778
779 if ( ! is_array($where))
780 {
781 $dest = array($where);
782 }
783 else
784 {
785 $dest = array();
786 foreach ($where as $key => $val)
787 {
788 $prefix = (count($dest) == 0) ? '' : ' AND ';
789
790 if ($val != '')
791 {
792 if ( ! $this->_has_operator($key))
793 {
794 $key .= ' =';
795 }
796
797 $val = ' '.$this->escape($val);
798 }
799
800 $dest[] = $prefix.$key.$val;
801 }
802 }
803
804 return $this->_update($this->dbprefix.$table, $fields, $dest);
805 }
admin7b613c72006-09-24 18:05:17 +0000806
807 // --------------------------------------------------------------------
808
809 /**
810 * Enables a native PHP function to be run, using a platform agnostic wrapper.
811 *
812 * @access public
813 * @param string the function name
814 * @param mixed any parameters needed by the function
815 * @return mixed
816 */
817 function call_function($function)
818 {
819 $driver = ($this->dbdriver == 'postgre') ? 'pg_' : $this->dbdriver.'_';
820
821 if (FALSE === strpos($driver, $function))
822 {
823 $function = $driver.$function;
824 }
825
826 if ( ! function_exists($function))
827 {
828 if ($this->db_debug)
829 {
830 return $this->display_error('db_unsupported_function');
831 }
832 return FALSE;
833 }
834 else
835 {
adminee54c112006-09-28 17:13:38 +0000836 $args = (func_num_args() > 1) ? array_splice(func_get_args(), 1) : null;
837
admin7b613c72006-09-24 18:05:17 +0000838 return call_user_func_array($function, $args);
839 }
840 }
admine8f6eb62006-10-02 06:46:16 +0000841
842 // --------------------------------------------------------------------
843
844 /**
845 * Set Cache Path
846 *
847 * @access public
848 * @param string the path to the cache directory
849 * @return void
850 */
851 function set_cache_path($path = '')
852 {
853 if ( ! is_dir($path) OR ! is_writable($path))
854 {
855 if ($this->db_debug)
856 {
857 return $this->display_error('db_invalid_cache_path');
858 }
859
860 $this->enable_caching(FALSE);
861 return FALSE;
862 }
863
864 $this->cache_dir = $path;
865 }
866
867 // --------------------------------------------------------------------
868
869 /**
870 * Enable Query Caching
871 *
872 * @access public
873 * @return void
874 */
875 function cache_on()
876 {
877 $this->query_caching = TRUE;
878 }
879
880 // --------------------------------------------------------------------
881
882 /**
883 * Disable Query Caching
884 *
885 * @access public
886 * @return void
887 */
888 function cache_off()
889 {
890 $this->query_caching = FALSE;
891 }
892
893 // --------------------------------------------------------------------
894
895 /**
896 * Load Caching Class
897 *
898 * @access private
899 * @return object
900 */
901 function _load_cache_class()
902 {
903 static $CACHE = NULL;
904
905 if (is_object($CACHE))
906 {
907 return $CACHE;
908 }
909
910 require_once BASEPATH.'database/DB_cache'.EXT;
911 $CACHE = new DB_cache();
912 return $CACHE;
913 }
admin7b613c72006-09-24 18:05:17 +0000914
915 // --------------------------------------------------------------------
916
917 /**
918 * Close DB Connection
919 *
920 * @access public
921 * @return void
922 */
923 function close()
924 {
925 if (is_resource($this->conn_id))
926 {
927 $this->_close($this->conn_id);
928 }
929 $this->conn_id = FALSE;
930 }
931
932 // --------------------------------------------------------------------
933
934 /**
935 * Display an error message
936 *
937 * @access public
938 * @param string the error message
939 * @param string any "swap" values
940 * @param boolean whether to localize the message
941 * @return string sends the application/errror_db.php template
942 */
943 function display_error($error = '', $swap = '', $native = FALSE)
944 {
945 $LANG = new CI_Language();
946 $LANG->load('db');
947
948 $heading = 'MySQL Error';
949
950 if ($native == TRUE)
951 {
952 $message = $error;
953 }
954 else
955 {
956 $message = ( ! is_array($error)) ? array(str_replace('%s', $swap, $LANG->line($error))) : $error;
957 }
958
959 if ( ! class_exists('CI_Exceptions'))
960 {
961 include_once(BASEPATH.'libraries/Exceptions'.EXT);
962 }
963
964 $error = new CI_Exceptions();
965 echo $error->show_error('An Error Was Encountered', $message, 'error_db');
966 exit;
967
968 }
969
970}
971
972?>