blob: 5f63a377160efb224ebe87df140eeae0625bf97c [file] [log] [blame]
Timothy Warren80ab8162011-08-22 18:26:12 -04001<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
2/**
3 * CodeIgniter
4 *
5 * An open source application development framework for PHP 5.1.6 or newer
6 *
Timothy Warrend1a5ba22011-10-21 04:45:28 -04007 * NOTICE OF LICENSE
8 *
9 * Licensed under the Open Software License version 3.0
10 *
11 * 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 *
Timothy Warren80ab8162011-08-22 18:26:12 -040019 * @package CodeIgniter
Timothy Warrend1a5ba22011-10-21 04:45:28 -040020 * @author EllisLab Dev Team
21 * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/)
22 * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
Timothy Warren80ab8162011-08-22 18:26:12 -040023 * @link http://codeigniter.com
Timothy Warren018af7a2011-09-07 12:07:35 -040024 * @since Version 2.1.0
Timothy Warren80ab8162011-08-22 18:26:12 -040025 * @filesource
26 */
27
28// ------------------------------------------------------------------------
29
30/**
Timothy Warren02615962011-08-24 08:21:36 -040031 * PDO Database Adapter Class
Timothy Warren80ab8162011-08-22 18:26:12 -040032 *
33 * Note: _DB is an extender class that the app controller
34 * creates dynamically based on whether the active record
35 * class is being used or not.
36 *
37 * @package CodeIgniter
38 * @subpackage Drivers
39 * @category Database
Timothy Warrend1a5ba22011-10-21 04:45:28 -040040 * @author EllisLab Dev Team
Timothy Warren80ab8162011-08-22 18:26:12 -040041 * @link http://codeigniter.com/user_guide/database/
42 */
43class CI_DB_pdo_driver extends CI_DB {
44
45 var $dbdriver = 'pdo';
46
47 // the character used to excape - not necessary for PDO
48 var $_escape_char = '';
Timothy Warrenc7ba6642011-09-14 12:25:14 -040049 var $_like_escape_str;
50 var $_like_escape_chr;
51
Timothy Warren80ab8162011-08-22 18:26:12 -040052
53 /**
54 * The syntax to count rows is slightly different across different
55 * database engines, so this string appears in each driver and is
56 * used for the count_all() and count_all_results() functions.
57 */
58 var $_count_string = "SELECT COUNT(*) AS ";
59 var $_random_keyword;
Timothy Warren7aae3682011-10-25 10:37:31 -040060
61 var $options = array();
Timothy Warren80ab8162011-08-22 18:26:12 -040062
Timothy Warren51b0e642011-09-13 13:30:27 -040063 function __construct($params)
Timothy Warren80ab8162011-08-22 18:26:12 -040064 {
Timothy Warrenb5a43b02011-10-04 17:26:04 -040065 parent::__construct($params);
Timothy Warrenab347582011-08-23 12:29:29 -040066
Timothy Warrenc7ba6642011-09-14 12:25:14 -040067 // clause and character used for LIKE escape sequences
Timothy Warrend6691532011-10-07 10:03:01 -040068 if (strpos($this->hostname, 'mysql') !== FALSE)
Timothy Warrenc7ba6642011-09-14 12:25:14 -040069 {
70 $this->_like_escape_str = '';
71 $this->_like_escape_chr = '';
Timothy Warrend1a5ba22011-10-21 04:45:28 -040072
Timothy Warren7d834be2011-10-26 11:26:17 -040073 //Prior to this version, the charset can't be set in the dsn
74 if(is_php('5.3.6'))
75 {
76 $this->hostname .= ";charset={$this->char_set}";
77 }
78
Timothy Warren7aae3682011-10-25 10:37:31 -040079 //Set the charset with the connection options
80 $this->options['PDO::MYSQL_ATTR_INIT_COMMAND'] = "SET NAMES {$this->char_set}";
Timothy Warrenc7ba6642011-09-14 12:25:14 -040081 }
Timothy Warrend6691532011-10-07 10:03:01 -040082 else if (strpos($this->hostname, 'odbc') !== FALSE)
Timothy Warrenc7ba6642011-09-14 12:25:14 -040083 {
84 $this->_like_escape_str = " {escape '%s'} ";
85 $this->_like_escape_chr = '!';
86 }
87 else
88 {
89 $this->_like_escape_str = " ESCAPE '%s' ";
90 $this->_like_escape_chr = '!';
91 }
92
Timothy Warrend93393f2011-10-26 11:31:49 -040093 $this->hostname .= ";dbname=".$this->database;
Timothy Warrend1a5ba22011-10-21 04:45:28 -040094
Timothy Warrenab347582011-08-23 12:29:29 -040095 $this->trans_enabled = FALSE;
Timothy Warren80ab8162011-08-22 18:26:12 -040096
97 $this->_random_keyword = ' RND('.time().')'; // database specific random keyword
98 }
99
100 /**
101 * Non-persistent database connection
102 *
103 * @access private called by the base class
104 * @return resource
105 */
106 function db_connect()
107 {
Timothy Warren7aae3682011-10-25 10:37:31 -0400108 $this->options['PDO::ATTR_ERRMODE'] = PDO::ERRMODE_SILENT;
Timothy Warrend93393f2011-10-26 11:31:49 -0400109
110 return new PDO($this->hostname, $this->username, $this->password, $this->options);
Timothy Warren80ab8162011-08-22 18:26:12 -0400111 }
112
113 // --------------------------------------------------------------------
114
115 /**
116 * Persistent database connection
117 *
118 * @access private called by the base class
119 * @return resource
120 */
121 function db_pconnect()
122 {
Timothy Warrend93393f2011-10-26 11:31:49 -0400123 $this->options['PDO::ATTR_ERRMODE'] = PDO::ERRMODE_SILENT;
124 $this->options['PDO::ATTR_PERSISTENT'] = TRUE;
125
126 return new PDO($this->hostname, $this->username, $this->password, $this->options);
Timothy Warren80ab8162011-08-22 18:26:12 -0400127 }
128
129 // --------------------------------------------------------------------
130
131 /**
132 * Reconnect
133 *
134 * Keep / reestablish the db connection if no queries have been
135 * sent for a length of time exceeding the server's idle timeout
136 *
137 * @access public
138 * @return void
139 */
140 function reconnect()
141 {
Timothy Warren02615962011-08-24 08:21:36 -0400142 if ($this->db->db_debug)
143 {
144 return $this->db->display_error('db_unsuported_feature');
145 }
146 return FALSE;
Timothy Warren80ab8162011-08-22 18:26:12 -0400147 }
148
149 // --------------------------------------------------------------------
150
151 /**
152 * Select the database
153 *
154 * @access private called by the base class
155 * @return resource
156 */
157 function db_select()
158 {
159 // Not needed for PDO
160 return TRUE;
161 }
162
163 // --------------------------------------------------------------------
164
165 /**
166 * Set client character set
167 *
168 * @access public
169 * @param string
170 * @param string
171 * @return resource
172 */
173 function db_set_charset($charset, $collation)
174 {
175 // @todo - add support if needed
176 return TRUE;
177 }
178
179 // --------------------------------------------------------------------
180
181 /**
182 * Version number query string
183 *
184 * @access public
185 * @return string
186 */
187 function _version()
188 {
Timothy Warren36fb8de2011-08-24 08:29:05 -0400189 return $this->conn_id->getAttribute(PDO::ATTR_CLIENT_VERSION);
Timothy Warren80ab8162011-08-22 18:26:12 -0400190 }
191
192 // --------------------------------------------------------------------
193
194 /**
195 * Execute the query
196 *
197 * @access private called by the base class
198 * @param string an SQL query
Timothy Warren51a48882011-09-14 13:47:06 -0400199 * @return object
Timothy Warren80ab8162011-08-22 18:26:12 -0400200 */
201 function _execute($sql)
202 {
203 $sql = $this->_prep_query($sql);
Timothy Warren51a48882011-09-14 13:47:06 -0400204 $result_id = $this->conn_id->query($sql);
205
Timothy Warrend6691532011-10-07 10:03:01 -0400206 if (is_object($result_id))
Timothy Warrenb5a43b02011-10-04 17:26:04 -0400207 {
208 $this->affect_rows = $result_id->rowCount();
209 }
210 else
211 {
212 $this->affect_rows = 0;
213 }
Timothy Warren51a48882011-09-14 13:47:06 -0400214
215 return $result_id;
Timothy Warren80ab8162011-08-22 18:26:12 -0400216 }
217
218 // --------------------------------------------------------------------
219
220 /**
221 * Prep the query
222 *
223 * If needed, each database adapter can prep the query string
224 *
225 * @access private called by execute()
226 * @param string an SQL query
227 * @return string
228 */
229 function _prep_query($sql)
230 {
231 return $sql;
232 }
233
234 // --------------------------------------------------------------------
235
236 /**
237 * Begin Transaction
238 *
239 * @access public
240 * @return bool
241 */
242 function trans_begin($test_mode = FALSE)
243 {
244 if ( ! $this->trans_enabled)
245 {
246 return TRUE;
247 }
248
249 // When transactions are nested we only begin/commit/rollback the outermost ones
250 if ($this->_trans_depth > 0)
251 {
252 return TRUE;
253 }
254
255 // Reset the transaction failure flag.
256 // If the $test_mode flag is set to TRUE transactions will be rolled back
257 // even if the queries produce a successful result.
Phil Sturgeonc00a5a02011-11-22 15:25:32 +0000258<<<<<<< HEAD
Timothy Warren80ab8162011-08-22 18:26:12 -0400259 $this->_trans_failure = ($test_mode === TRUE) ? TRUE : FALSE;
Phil Sturgeonc00a5a02011-11-22 15:25:32 +0000260=======
Timothy Warrend019fd62011-10-26 11:26:17 -0400261 $this->_trans_failure = (bool) ($test_mode === TRUE);
Phil Sturgeonc00a5a02011-11-22 15:25:32 +0000262>>>>>>> master
Timothy Warren80ab8162011-08-22 18:26:12 -0400263
Timothy Warrenab347582011-08-23 12:29:29 -0400264 return $this->conn_id->beginTransaction();
Timothy Warren80ab8162011-08-22 18:26:12 -0400265 }
266
267 // --------------------------------------------------------------------
268
269 /**
270 * Commit Transaction
271 *
272 * @access public
273 * @return bool
274 */
275 function trans_commit()
276 {
277 if ( ! $this->trans_enabled)
278 {
279 return TRUE;
280 }
281
282 // When transactions are nested we only begin/commit/rollback the outermost ones
283 if ($this->_trans_depth > 0)
284 {
285 return TRUE;
286 }
287
Timothy Warrenab347582011-08-23 12:29:29 -0400288 $ret = $this->conn->commit();
Timothy Warren80ab8162011-08-22 18:26:12 -0400289 return $ret;
290 }
291
292 // --------------------------------------------------------------------
293
294 /**
295 * Rollback Transaction
296 *
297 * @access public
298 * @return bool
299 */
300 function trans_rollback()
301 {
302 if ( ! $this->trans_enabled)
303 {
304 return TRUE;
305 }
306
307 // When transactions are nested we only begin/commit/rollback the outermost ones
308 if ($this->_trans_depth > 0)
309 {
310 return TRUE;
311 }
312
Timothy Warrenab347582011-08-23 12:29:29 -0400313 $ret = $this->conn_id->rollBack();
Timothy Warren80ab8162011-08-22 18:26:12 -0400314 return $ret;
315 }
316
317 // --------------------------------------------------------------------
318
319 /**
320 * Escape String
321 *
322 * @access public
323 * @param string
324 * @param bool whether or not the string will be used in a LIKE condition
325 * @return string
326 */
327 function escape_str($str, $like = FALSE)
328 {
329 if (is_array($str))
330 {
331 foreach ($str as $key => $val)
332 {
333 $str[$key] = $this->escape_str($val, $like);
334 }
335
336 return $str;
337 }
Timothy Warrenb5a43b02011-10-04 17:26:04 -0400338
Timothy Warren47663972011-10-05 16:44:50 -0400339 //Escape the string
340 $str = $this->conn_id->quote($str);
Timothy Warrenb5a43b02011-10-04 17:26:04 -0400341
Timothy Warren47663972011-10-05 16:44:50 -0400342 //If there are duplicated quotes, trim them away
Timothy Warrend6691532011-10-07 10:03:01 -0400343 if (strpos($str, "'") === 0)
Timothy Warrenec193322011-10-07 09:53:35 -0400344 {
345 $str = substr($str, 1, -1);
346 }
347
Timothy Warren80ab8162011-08-22 18:26:12 -0400348 // escape LIKE condition wildcards
349 if ($like === TRUE)
350 {
351 $str = str_replace( array('%', '_', $this->_like_escape_chr),
352 array($this->_like_escape_chr.'%', $this->_like_escape_chr.'_', $this->_like_escape_chr.$this->_like_escape_chr),
353 $str);
354 }
355
356 return $str;
357 }
358
359 // --------------------------------------------------------------------
360
361 /**
362 * Affected Rows
363 *
364 * @access public
365 * @return integer
366 */
367 function affected_rows()
368 {
Timothy Warren51a48882011-09-14 13:47:06 -0400369 return $this->affect_rows;
Timothy Warren80ab8162011-08-22 18:26:12 -0400370 }
371
372 // --------------------------------------------------------------------
373
374 /**
375 * Insert ID
Timothy Warren57cea512011-09-14 14:26:28 -0400376 *
Timothy Warren80ab8162011-08-22 18:26:12 -0400377 * @access public
378 * @return integer
379 */
Timothy Warren51a48882011-09-14 13:47:06 -0400380 function insert_id($name=NULL)
Timothy Warren80ab8162011-08-22 18:26:12 -0400381 {
Timothy Warren33512752011-10-07 09:51:49 -0400382 //Convenience method for postgres insertid
Timothy Warrend6691532011-10-07 10:03:01 -0400383 if (strpos($this->hostname, 'pgsql') !== FALSE)
Timothy Warren33512752011-10-07 09:51:49 -0400384 {
385 $v = $this->_version();
386
387 $table = func_num_args() > 0 ? func_get_arg(0) : NULL;
388
389 if ($table == NULL && $v >= '8.1')
390 {
391 $sql='SELECT LASTVAL() as ins_id';
392 }
393 $query = $this->query($sql);
394 $row = $query->row();
395 return $row->ins_id;
396 }
397 else
398 {
399 return $this->conn_id->lastInsertId($name);
400 }
Timothy Warren80ab8162011-08-22 18:26:12 -0400401 }
402
403 // --------------------------------------------------------------------
404
405 /**
406 * "Count All" query
407 *
408 * Generates a platform-specific query string that counts all records in
409 * the specified database
410 *
411 * @access public
412 * @param string
413 * @return string
414 */
415 function count_all($table = '')
416 {
417 if ($table == '')
418 {
419 return 0;
420 }
421
422 $query = $this->query($this->_count_string . $this->_protect_identifiers('numrows') . " FROM " . $this->_protect_identifiers($table, TRUE, NULL, FALSE));
423
424 if ($query->num_rows() == 0)
425 {
426 return 0;
427 }
428
429 $row = $query->row();
430 $this->_reset_select();
431 return (int) $row->numrows;
432 }
433
434 // --------------------------------------------------------------------
435
436 /**
437 * Show table query
438 *
439 * Generates a platform-specific query string so that the table names can be fetched
440 *
441 * @access private
442 * @param boolean
443 * @return string
444 */
445 function _list_tables($prefix_limit = FALSE)
446 {
447 $sql = "SHOW TABLES FROM `".$this->database."`";
448
449 if ($prefix_limit !== FALSE AND $this->dbprefix != '')
450 {
Timothy Warren33512752011-10-07 09:51:49 -0400451 //$sql .= " LIKE '".$this->escape_like_str($this->dbprefix)."%' ".sprintf($this->_like_escape_str, $this->_like_escape_chr);
Timothy Warren80ab8162011-08-22 18:26:12 -0400452 return FALSE; // not currently supported
453 }
454
455 return $sql;
456 }
457
458 // --------------------------------------------------------------------
459
460 /**
461 * Show column query
462 *
463 * Generates a platform-specific query string so that the column names can be fetched
464 *
465 * @access public
466 * @param string the table name
467 * @return string
468 */
469 function _list_columns($table = '')
470 {
471 return "SHOW COLUMNS FROM ".$table;
472 }
473
474 // --------------------------------------------------------------------
475
476 /**
477 * Field data query
478 *
479 * Generates a platform-specific query so that the column data can be retrieved
480 *
481 * @access public
482 * @param string the table name
483 * @return object
484 */
485 function _field_data($table)
486 {
487 return "SELECT TOP 1 FROM ".$table;
488 }
489
490 // --------------------------------------------------------------------
491
492 /**
493 * The error message string
494 *
495 * @access private
496 * @return string
497 */
498 function _error_message()
499 {
Timothy Warrenab347582011-08-23 12:29:29 -0400500 $error_array = $this->conn_id->errorInfo();
501 return $error_array[2];
Timothy Warren80ab8162011-08-22 18:26:12 -0400502 }
503
504 // --------------------------------------------------------------------
505
506 /**
507 * The error message number
508 *
509 * @access private
510 * @return integer
511 */
512 function _error_number()
513 {
Timothy Warrenab347582011-08-23 12:29:29 -0400514 return $this->conn_id->errorCode();
Timothy Warren80ab8162011-08-22 18:26:12 -0400515 }
516
517 // --------------------------------------------------------------------
518
519 /**
520 * Escape the SQL Identifiers
521 *
522 * This function escapes column and table names
523 *
524 * @access private
525 * @param string
526 * @return string
527 */
528 function _escape_identifiers($item)
529 {
530 if ($this->_escape_char == '')
531 {
532 return $item;
533 }
534
535 foreach ($this->_reserved_identifiers as $id)
536 {
537 if (strpos($item, '.'.$id) !== FALSE)
538 {
539 $str = $this->_escape_char. str_replace('.', $this->_escape_char.'.', $item);
540
541 // remove duplicates if the user already included the escape
542 return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str);
543 }
544 }
545
546 if (strpos($item, '.') !== FALSE)
547 {
548 $str = $this->_escape_char.str_replace('.', $this->_escape_char.'.'.$this->_escape_char, $item).$this->_escape_char;
Timothy Warren018af7a2011-09-07 12:07:35 -0400549
Timothy Warren80ab8162011-08-22 18:26:12 -0400550 }
551 else
552 {
553 $str = $this->_escape_char.$item.$this->_escape_char;
554 }
555
556 // remove duplicates if the user already included the escape
557 return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str);
558 }
559
560 // --------------------------------------------------------------------
561
562 /**
563 * From Tables
564 *
565 * This function implicitly groups FROM tables so there is no confusion
566 * about operator precedence in harmony with SQL standards
567 *
568 * @access public
569 * @param type
570 * @return type
571 */
572 function _from_tables($tables)
573 {
574 if ( ! is_array($tables))
575 {
576 $tables = array($tables);
577 }
578
Timothy Warrenab347582011-08-23 12:29:29 -0400579 return (count($tables) == 1) ? $tables[0] : '('.implode(', ', $tables).')';
Timothy Warren80ab8162011-08-22 18:26:12 -0400580 }
581
582 // --------------------------------------------------------------------
583
584 /**
585 * Insert statement
586 *
587 * Generates a platform-specific insert string from the supplied data
588 *
589 * @access public
590 * @param string the table name
591 * @param array the insert keys
592 * @param array the insert values
593 * @return string
594 */
595 function _insert($table, $keys, $values)
596 {
597 return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")";
598 }
Timothy Warrenb5a43b02011-10-04 17:26:04 -0400599
600 // --------------------------------------------------------------------
601
602 /**
603 * Insert_batch statement
604 *
605 * Generates a platform-specific insert string from the supplied data
606 *
607 * @access public
608 * @param string the table name
609 * @param array the insert keys
610 * @param array the insert values
611 * @return string
612 */
613 function _insert_batch($table, $keys, $values)
614 {
615 return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES ".implode(', ', $values);
616 }
Timothy Warren80ab8162011-08-22 18:26:12 -0400617
618 // --------------------------------------------------------------------
619
620 /**
621 * Update statement
622 *
623 * Generates a platform-specific update string from the supplied data
624 *
625 * @access public
626 * @param string the table name
627 * @param array the update data
628 * @param array the where clause
629 * @param array the orderby clause
630 * @param array the limit clause
631 * @return string
632 */
633 function _update($table, $values, $where, $orderby = array(), $limit = FALSE)
634 {
635 foreach ($values as $key => $val)
636 {
637 $valstr[] = $key." = ".$val;
638 }
639
640 $limit = ( ! $limit) ? '' : ' LIMIT '.$limit;
641
642 $orderby = (count($orderby) >= 1)?' ORDER BY '.implode(", ", $orderby):'';
643
644 $sql = "UPDATE ".$table." SET ".implode(', ', $valstr);
645
646 $sql .= ($where != '' AND count($where) >=1) ? " WHERE ".implode(" ", $where) : '';
647
648 $sql .= $orderby.$limit;
649
650 return $sql;
651 }
Timothy Warrenb5a43b02011-10-04 17:26:04 -0400652
653 // --------------------------------------------------------------------
654
655 /**
656 * Update_Batch statement
657 *
658 * Generates a platform-specific batch update string from the supplied data
659 *
660 * @access public
661 * @param string the table name
662 * @param array the update data
663 * @param array the where clause
664 * @return string
665 */
666 function _update_batch($table, $values, $index, $where = NULL)
667 {
668 $ids = array();
669 $where = ($where != '' AND count($where) >=1) ? implode(" ", $where).' AND ' : '';
670
671 foreach ($values as $key => $val)
672 {
673 $ids[] = $val[$index];
674
675 foreach (array_keys($val) as $field)
676 {
677 if ($field != $index)
678 {
679 $final[$field][] = 'WHEN '.$index.' = '.$val[$index].' THEN '.$val[$field];
680 }
681 }
682 }
683
684 $sql = "UPDATE ".$table." SET ";
685 $cases = '';
686
687 foreach ($final as $k => $v)
688 {
689 $cases .= $k.' = CASE '."\n";
690 foreach ($v as $row)
691 {
692 $cases .= $row."\n";
693 }
694
695 $cases .= 'ELSE '.$k.' END, ';
696 }
697
698 $sql .= substr($cases, 0, -2);
699
700 $sql .= ' WHERE '.$where.$index.' IN ('.implode(',', $ids).')';
701
702 return $sql;
703 }
Timothy Warren80ab8162011-08-22 18:26:12 -0400704
705
706 // --------------------------------------------------------------------
707
708 /**
709 * Truncate statement
710 *
711 * Generates a platform-specific truncate string from the supplied data
712 * If the database does not support the truncate() command
713 * This function maps to "DELETE FROM table"
714 *
715 * @access public
716 * @param string the table name
717 * @return string
718 */
719 function _truncate($table)
720 {
721 return $this->_delete($table);
722 }
723
724 // --------------------------------------------------------------------
725
726 /**
727 * Delete statement
728 *
729 * Generates a platform-specific delete string from the supplied data
730 *
731 * @access public
732 * @param string the table name
733 * @param array the where clause
734 * @param string the limit clause
735 * @return string
736 */
737 function _delete($table, $where = array(), $like = array(), $limit = FALSE)
738 {
739 $conditions = '';
740
741 if (count($where) > 0 OR count($like) > 0)
742 {
743 $conditions = "\nWHERE ";
744 $conditions .= implode("\n", $this->ar_where);
745
746 if (count($where) > 0 && count($like) > 0)
747 {
748 $conditions .= " AND ";
749 }
750 $conditions .= implode("\n", $like);
751 }
752
753 $limit = ( ! $limit) ? '' : ' LIMIT '.$limit;
754
755 return "DELETE FROM ".$table.$conditions.$limit;
756 }
757
758 // --------------------------------------------------------------------
759
760 /**
761 * Limit string
762 *
763 * Generates a platform-specific LIMIT clause
764 *
765 * @access public
766 * @param string the sql query string
767 * @param integer the number of rows to limit the query to
768 * @param integer the offset value
769 * @return string
770 */
771 function _limit($sql, $limit, $offset)
772 {
Timothy Warrend6691532011-10-07 10:03:01 -0400773 if (strpos($this->hostname, 'cubrid') !== FALSE || strpos($this->hostname, 'sqlite') !== FALSE)
Timothy Warren0a43ad82011-09-15 20:15:19 -0400774 {
775 if ($offset == 0)
776 {
777 $offset = '';
778 }
779 else
780 {
781 $offset .= ", ";
782 }
783
784 return $sql."LIMIT ".$offset.$limit;
785 }
786 else
787 {
788 $sql .= "LIMIT ".$limit;
789
790 if ($offset > 0)
791 {
792 $sql .= " OFFSET ".$offset;
793 }
794
795 return $sql;
796 }
Timothy Warren80ab8162011-08-22 18:26:12 -0400797 }
798
799 // --------------------------------------------------------------------
800
801 /**
802 * Close DB Connection
803 *
804 * @access public
805 * @param resource
806 * @return void
807 */
808 function _close($conn_id)
809 {
Timothy Warren6a450cf2011-08-23 12:46:11 -0400810 $this->conn_id = null;
Timothy Warren80ab8162011-08-22 18:26:12 -0400811 }
812
813
814}
815
816
817
818/* End of file pdo_driver.php */
819/* Location: ./system/database/drivers/pdo/pdo_driver.php */