3 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
6 * Contains the DB_common base class
10 * LICENSE: This source file is subject to version 3.0 of the PHP license
11 * that is available through the world-wide-web at the following URI:
12 * http://www.php.net/license/3_0.txt. If you did not receive a copy of
13 * the PHP License and are unable to obtain it through the web, please
14 * send a note to license@php.net so we can mail you a copy immediately.
18 * @author Stig Bakken <ssb@php.net>
19 * @author Tomas V.V. Cox <cox@idecnet.com>
20 * @author Daniel Convissor <danielc@php.net>
21 * @copyright 1997-2007 The PHP Group
22 * @license http://www.php.net/license/3_0.txt PHP License 3.0
24 * @link http://pear.php.net/package/DB
28 * Obtain the PEAR class so it can be extended from
30 require_once 'lib/pear/PEAR.php';
33 * DB_common is the base class from which each database driver class extends
35 * All common methods are declared here. If a given DBMS driver contains
36 * a particular method, that method will overload the one here.
40 * @author Stig Bakken <ssb@php.net>
41 * @author Tomas V.V. Cox <cox@idecnet.com>
42 * @author Daniel Convissor <danielc@php.net>
43 * @copyright 1997-2007 The PHP Group
44 * @license http://www.php.net/license/3_0.txt PHP License 3.0
45 * @version Release: 1.10.0
46 * @link http://pear.php.net/package/DB
48 class DB_common extends PEAR
53 * The current default fetch mode
56 var $fetchmode = DB_FETCHMODE_ORDERED;
59 * The name of the class into which results should be fetched when
60 * DB_FETCHMODE_OBJECT is in effect
64 var $fetchmode_object_class = 'stdClass';
67 * Was a connection present when the object was serialized()?
69 * @see DB_common::__sleep(), DB_common::__wake()
71 var $was_connected = null;
74 * The most recently executed query
80 * Run-time configuration options
82 * The 'optimize' option has been deprecated. Use the 'portability'
86 * @see DB_common::setOption()
89 'result_buffering' => 500,
90 'persistent' => false,
93 'seqname_format' => '%s_seq',
95 'portability' => DB_PORTABILITY_NONE,
96 'optimize' => 'performance', // Deprecated. Use 'portability'.
100 * The parameters from the most recently executed query
102 * @since Property available since Release 1.7.0
104 var $last_parameters = array();
107 * The elements from each prepared statement
110 var $prepare_tokens = array();
113 * The data types of the various elements in each prepared statement
116 var $prepare_types = array();
119 * The prepared queries
122 var $prepared_queries = array();
125 * Flag indicating that the last query was a manipulation query.
129 var $_last_query_manip = false;
132 * Flag indicating that the next query <em>must</em> be a manipulation
137 var $_next_query_manip = false;
144 * This constructor calls <kbd>$this->PEAR('DB_Error')</kbd>
148 function __construct()
150 $this->PEAR('DB_Error');
157 * Automatically indicates which properties should be saved
158 * when PHP's serialize() function is called
160 * @return array the array of properties names that should be saved
164 if ($this->connection) {
165 // Don't disconnect(), people use serialize() for many reasons
166 $this->was_connected = true;
168 $this->was_connected = false;
170 if (isset($this->autocommit)) {
171 return array('autocommit',
176 'fetchmode_object_class',
181 return array('dbsyntax',
185 'fetchmode_object_class',
196 * Automatically reconnects to the database when PHP's unserialize()
199 * The reconnection attempt is only performed if the object was connected
200 * at the time PHP's serialize() function was run.
206 if ($this->was_connected) {
207 $this->connect($this->dsn, $this->options['persistent']);
215 * Automatic string conversion for PHP 5
217 * @return string a string describing the current PEAR DB object
219 * @since Method available since Release 1.7.0
221 function __toString()
223 $info = strtolower(get_class($this));
224 $info .= ': (phptype=' . $this->phptype .
225 ', dbsyntax=' . $this->dbsyntax .
227 if ($this->connection) {
228 $info .= ' [connected]';
237 * DEPRECATED: String conversion method
239 * @return string a string describing the current PEAR DB object
241 * @deprecated Method deprecated in Release 1.7.0
245 return $this->__toString();
252 * DEPRECATED: Quotes a string so it can be safely used within string
253 * delimiters in a query
255 * @param string $string the string to be quoted
257 * @return string the quoted string
259 * @see DB_common::quoteSmart(), DB_common::escapeSimple()
260 * @deprecated Method deprecated some time before Release 1.2
262 function quoteString($string)
264 $string = $this->quoteSmart($string);
265 if ($string[0] == "'") {
266 return substr($string, 1, -1);
275 * DEPRECATED: Quotes a string so it can be safely used in a query
277 * @param string $string the string to quote
279 * @return string the quoted string or the string <samp>NULL</samp>
280 * if the value submitted is <kbd>null</kbd>.
282 * @see DB_common::quoteSmart(), DB_common::escapeSimple()
283 * @deprecated Deprecated in release 1.6.0
285 function quote($string = null)
287 return $this->quoteSmart($string);
291 // {{{ quoteIdentifier()
294 * Quotes a string so it can be safely used as a table or column name
296 * Delimiting style depends on which database driver is being used.
298 * NOTE: just because you CAN use delimited identifiers doesn't mean
299 * you SHOULD use them. In general, they end up causing way more
300 * problems than they solve.
302 * Portability is broken by using the following characters inside
303 * delimited identifiers:
304 * + backtick (<kbd>`</kbd>) -- due to MySQL
305 * + double quote (<kbd>"</kbd>) -- due to Oracle
306 * + brackets (<kbd>[</kbd> or <kbd>]</kbd>) -- due to Access
308 * Delimited identifiers are known to generally work correctly under
309 * the following drivers:
318 * + sybase (must execute <kbd>set quoted_identifier on</kbd> sometime
321 * InterBase doesn't seem to be able to use delimited identifiers
322 * via PHP 4. They work fine under PHP 5.
324 * @param string $str the identifier name to be quoted
326 * @return string the quoted identifier
328 * @since Method available since Release 1.6.0
330 function quoteIdentifier($str)
332 return '"' . str_replace('"', '""', $str) . '"';
339 * Formats input so it can be safely used in a query
341 * The output depends on the PHP data type of input and the database
344 * @param mixed $in the data to be formatted
346 * @return mixed the formatted data. The format depends on the input's
350 * <kbd>input</kbd> -> <samp>returns</samp>
353 * <kbd>null</kbd> -> the string <samp>NULL</samp>
356 * <kbd>integer</kbd> or <kbd>double</kbd> -> the unquoted number
359 * <kbd>bool</kbd> -> output depends on the driver in use
360 * Most drivers return integers: <samp>1</samp> if
361 * <kbd>true</kbd> or <samp>0</samp> if
363 * Some return strings: <samp>TRUE</samp> if
364 * <kbd>true</kbd> or <samp>FALSE</samp> if
366 * Finally one returns strings: <samp>T</samp> if
367 * <kbd>true</kbd> or <samp>F</samp> if
368 * <kbd>false</kbd>. Here is a list of each DBMS,
369 * the values returned and the suggested column type:
372 * <kbd>dbase</kbd> -> <samp>T/F</samp>
373 * (<kbd>Logical</kbd>)
376 * <kbd>fbase</kbd> -> <samp>TRUE/FALSE</samp>
377 * (<kbd>BOOLEAN</kbd>)
380 * <kbd>ibase</kbd> -> <samp>1/0</samp>
381 * (<kbd>SMALLINT</kbd>) [1]
384 * <kbd>ifx</kbd> -> <samp>1/0</samp>
385 * (<kbd>SMALLINT</kbd>) [1]
388 * <kbd>msql</kbd> -> <samp>1/0</samp>
389 * (<kbd>INTEGER</kbd>)
392 * <kbd>mssql</kbd> -> <samp>1/0</samp>
396 * <kbd>mysql</kbd> -> <samp>1/0</samp>
397 * (<kbd>TINYINT(1)</kbd>)
400 * <kbd>mysqli</kbd> -> <samp>1/0</samp>
401 * (<kbd>TINYINT(1)</kbd>)
404 * <kbd>oci8</kbd> -> <samp>1/0</samp>
405 * (<kbd>NUMBER(1)</kbd>)
408 * <kbd>odbc</kbd> -> <samp>1/0</samp>
409 * (<kbd>SMALLINT</kbd>) [1]
412 * <kbd>pgsql</kbd> -> <samp>TRUE/FALSE</samp>
413 * (<kbd>BOOLEAN</kbd>)
416 * <kbd>sqlite</kbd> -> <samp>1/0</samp>
417 * (<kbd>INTEGER</kbd>)
420 * <kbd>sybase</kbd> -> <samp>1/0</samp>
421 * (<kbd>TINYINT(1)</kbd>)
424 * [1] Accommodate the lowest common denominator because not all
425 * versions of have <kbd>BOOLEAN</kbd>.
428 * other (including strings and numeric strings) ->
429 * the data with single quotes escaped by preceeding
430 * single quotes, backslashes are escaped by preceeding
431 * backslashes, then the whole string is encapsulated
432 * between single quotes
436 * @see DB_common::escapeSimple()
437 * @since Method available since Release 1.6.0
439 function quoteSmart($in)
443 } elseif (is_float($in)) {
444 return $this->quoteFloat($in);
445 } elseif (is_bool($in)) {
446 return $this->quoteBoolean($in);
447 } elseif (is_null($in)) {
450 if ($this->dbsyntax == 'access'
451 && preg_match('/^#.+#$/', $in))
453 return $this->escapeSimple($in);
455 return "'" . $this->escapeSimple($in) . "'";
460 // {{{ quoteBoolean()
463 * Formats a boolean value for use within a query in a locale-independent
466 * @param boolean the boolean value to be quoted.
467 * @return string the quoted string.
468 * @see DB_common::quoteSmart()
469 * @since Method available since release 1.7.8.
471 function quoteBoolean($boolean) {
472 return $boolean ? '1' : '0';
479 * Formats a float value for use within a query in a locale-independent
482 * @param float the float value to be quoted.
483 * @return string the quoted string.
484 * @see DB_common::quoteSmart()
485 * @since Method available since release 1.7.8.
487 function quoteFloat($float) {
488 return "'".$this->escapeSimple(str_replace(',', '.', strval(floatval($float))))."'";
492 // {{{ escapeSimple()
495 * Escapes a string according to the current DBMS's standards
497 * In SQLite, this makes things safe for inserts/updates, but may
498 * cause problems when performing text comparisons against columns
499 * containing binary data. See the
500 * {@link http://php.net/sqlite_escape_string PHP manual} for more info.
502 * @param string $str the string to be escaped
504 * @return string the escaped string
506 * @see DB_common::quoteSmart()
507 * @since Method available since Release 1.6.0
509 function escapeSimple($str)
511 return str_replace("'", "''", $str);
518 * Tells whether the present driver supports a given feature
520 * @param string $feature the feature you're curious about
522 * @return bool whether this driver supports $feature
524 function provides($feature)
526 return $this->features[$feature];
530 // {{{ setFetchMode()
533 * Sets the fetch mode that should be used by default for query results
535 * @param integer $fetchmode DB_FETCHMODE_ORDERED, DB_FETCHMODE_ASSOC
536 * or DB_FETCHMODE_OBJECT
537 * @param string $object_class the class name of the object to be returned
538 * by the fetch methods when the
539 * DB_FETCHMODE_OBJECT mode is selected.
540 * If no class is specified by default a cast
541 * to object from the assoc array row will be
542 * done. There is also the posibility to use
543 * and extend the 'DB_row' class.
545 * @see DB_FETCHMODE_ORDERED, DB_FETCHMODE_ASSOC, DB_FETCHMODE_OBJECT
547 function setFetchMode($fetchmode, $object_class = 'stdClass')
549 switch ($fetchmode) {
550 case DB_FETCHMODE_OBJECT:
551 $this->fetchmode_object_class = $object_class;
552 case DB_FETCHMODE_ORDERED:
553 case DB_FETCHMODE_ASSOC:
554 $this->fetchmode = $fetchmode;
557 return $this->raiseError('invalid fetchmode mode');
565 * Sets run-time configuration options for PEAR DB
567 * Options, their data types, default values and description:
570 * <var>autofree</var> <kbd>boolean</kbd> = <samp>false</samp>
571 * <br />should results be freed automatically when there are no
574 * <var>result_buffering</var> <kbd>integer</kbd> = <samp>500</samp>
575 * <br />how many rows of the result set should be buffered?
576 * <br />In mysql: mysql_unbuffered_query() is used instead of
577 * mysql_query() if this value is 0. (Release 1.7.0)
578 * <br />In oci8: this value is passed to ocisetprefetch().
581 * <var>debug</var> <kbd>integer</kbd> = <samp>0</samp>
584 * <var>persistent</var> <kbd>boolean</kbd> = <samp>false</samp>
585 * <br />should the connection be persistent?
587 * <var>portability</var> <kbd>integer</kbd> = <samp>DB_PORTABILITY_NONE</samp>
588 * <br />portability mode constant (see below)
590 * <var>seqname_format</var> <kbd>string</kbd> = <samp>%s_seq</samp>
591 * <br />the sprintf() format string used on sequence names. This
592 * format is applied to sequence names passed to
593 * createSequence(), nextID() and dropSequence().
595 * <var>ssl</var> <kbd>boolean</kbd> = <samp>false</samp>
596 * <br />use ssl to connect?
600 * -----------------------------------------
604 * These modes are bitwised, so they can be combined using <kbd>|</kbd>
605 * and removed using <kbd>^</kbd>. See the examples section below on how
608 * <samp>DB_PORTABILITY_NONE</samp>
609 * turn off all portability features
611 * This mode gets automatically turned on if the deprecated
612 * <var>optimize</var> option gets set to <samp>performance</samp>.
615 * <samp>DB_PORTABILITY_LOWERCASE</samp>
616 * convert names of tables and fields to lower case when using
617 * <kbd>get*()</kbd>, <kbd>fetch*()</kbd> and <kbd>tableInfo()</kbd>
619 * This mode gets automatically turned on in the following databases
620 * if the deprecated option <var>optimize</var> gets set to
621 * <samp>portability</samp>:
625 * <samp>DB_PORTABILITY_RTRIM</samp>
626 * right trim the data output by <kbd>get*()</kbd> <kbd>fetch*()</kbd>
629 * <samp>DB_PORTABILITY_DELETE_COUNT</samp>
630 * force reporting the number of rows deleted
632 * Some DBMS's don't count the number of rows deleted when performing
633 * simple <kbd>DELETE FROM tablename</kbd> queries. This portability
634 * mode tricks such DBMS's into telling the count by adding
635 * <samp>WHERE 1=1</samp> to the end of <kbd>DELETE</kbd> queries.
637 * This mode gets automatically turned on in the following databases
638 * if the deprecated option <var>optimize</var> gets set to
639 * <samp>portability</samp>:
646 * <samp>DB_PORTABILITY_NUMROWS</samp>
647 * enable hack that makes <kbd>numRows()</kbd> work in Oracle
649 * This mode gets automatically turned on in the following databases
650 * if the deprecated option <var>optimize</var> gets set to
651 * <samp>portability</samp>:
655 * <samp>DB_PORTABILITY_ERRORS</samp>
656 * makes certain error messages in certain drivers compatible
657 * with those from other DBMS's
659 * + mysql, mysqli: change unique/primary key constraints
660 * DB_ERROR_ALREADY_EXISTS -> DB_ERROR_CONSTRAINT
662 * + odbc(access): MS's ODBC driver reports 'no such field' as code
663 * 07001, which means 'too few parameters.' When this option is on
664 * that code gets mapped to DB_ERROR_NOSUCHFIELD.
665 * DB_ERROR_MISMATCH -> DB_ERROR_NOSUCHFIELD
667 * <samp>DB_PORTABILITY_NULL_TO_EMPTY</samp>
668 * convert null values to empty strings in data output by get*() and
669 * fetch*(). Needed because Oracle considers empty strings to be null,
670 * while most other DBMS's know the difference between empty and null.
673 * <samp>DB_PORTABILITY_ALL</samp>
674 * turn on all portability features
676 * -----------------------------------------
678 * Example 1. Simple setOption() example
680 * $db->setOption('autofree', true);
683 * Example 2. Portability for lowercasing and trimming
685 * $db->setOption('portability',
686 * DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_RTRIM);
689 * Example 3. All portability options except trimming
691 * $db->setOption('portability',
692 * DB_PORTABILITY_ALL ^ DB_PORTABILITY_RTRIM);
695 * @param string $option option name
696 * @param mixed $value value for the option
698 * @return int DB_OK on success. A DB_Error object on failure.
700 * @see DB_common::$options
702 function setOption($option, $value)
704 if (isset($this->options[$option])) {
705 $this->options[$option] = $value;
708 * Backwards compatibility check for the deprecated 'optimize'
709 * option. Done here in case settings change after connecting.
711 if ($option == 'optimize') {
712 if ($value == 'portability') {
713 switch ($this->phptype) {
715 $this->options['portability'] =
716 DB_PORTABILITY_LOWERCASE |
717 DB_PORTABILITY_NUMROWS;
723 $this->options['portability'] =
724 DB_PORTABILITY_DELETE_COUNT;
728 $this->options['portability'] = DB_PORTABILITY_NONE;
734 return $this->raiseError("unknown option $option");
741 * Returns the value of an option
743 * @param string $option the option name you're curious about
745 * @return mixed the option's value
747 function getOption($option)
749 if (isset($this->options[$option])) {
750 return $this->options[$option];
752 return $this->raiseError("unknown option $option");
759 * Prepares a query for multiple execution with execute()
761 * Creates a query that can be run multiple times. Each time it is run,
762 * the placeholders, if any, will be replaced by the contents of
763 * execute()'s $data argument.
765 * Three types of placeholders can be used:
766 * + <kbd>?</kbd> scalar value (i.e. strings, integers). The system
767 * will automatically quote and escape the data.
768 * + <kbd>!</kbd> value is inserted 'as is'
769 * + <kbd>&</kbd> requires a file name. The file's contents get
770 * inserted into the query (i.e. saving binary
775 * $sth = $db->prepare('INSERT INTO tbl (a, b, c) VALUES (?, !, &)');
781 * $res = $db->execute($sth, $data);
784 * Use backslashes to escape placeholder characters if you don't want
785 * them to be interpreted as placeholders:
787 * "UPDATE foo SET col=? WHERE col='over \& under'"
790 * With some database backends, this is emulated.
792 * {@internal ibase and oci8 have their own prepare() methods.}}
794 * @param string $query the query to be prepared
796 * @return mixed DB statement resource on success. A DB_Error object
799 * @see DB_common::execute()
801 function prepare($query)
803 $tokens = preg_split('/((?<!\\\)[&?!])/', $query, -1,
804 PREG_SPLIT_DELIM_CAPTURE);
807 $newtokens = array();
809 foreach ($tokens as $val) {
812 $types[$token++] = DB_PARAM_SCALAR;
815 $types[$token++] = DB_PARAM_OPAQUE;
818 $types[$token++] = DB_PARAM_MISC;
821 $newtokens[] = preg_replace('/\\\([&?!])/', "\\1", $val);
825 $this->prepare_tokens[] = &$newtokens;
826 end($this->prepare_tokens);
828 $k = key($this->prepare_tokens);
829 $this->prepare_types[$k] = $types;
830 $this->prepared_queries[$k] = implode(' ', $newtokens);
839 * Automaticaly generates an insert or update query and pass it to prepare()
841 * @param string $table the table name
842 * @param array $table_fields the array of field names
843 * @param int $mode a type of query to make:
844 * DB_AUTOQUERY_INSERT or DB_AUTOQUERY_UPDATE
845 * @param string $where for update queries: the WHERE clause to
846 * append to the SQL statement. Don't
847 * include the "WHERE" keyword.
849 * @return resource the query handle
851 * @uses DB_common::prepare(), DB_common::buildManipSQL()
853 function autoPrepare($table, $table_fields, $mode = DB_AUTOQUERY_INSERT,
856 $query = $this->buildManipSQL($table, $table_fields, $mode, $where);
857 if (DB::isError($query)) {
860 return $this->prepare($query);
867 * Automaticaly generates an insert or update query and call prepare()
868 * and execute() with it
870 * @param string $table the table name
871 * @param array $fields_values the associative array where $key is a
872 * field name and $value its value
873 * @param int $mode a type of query to make:
874 * DB_AUTOQUERY_INSERT or DB_AUTOQUERY_UPDATE
875 * @param string $where for update queries: the WHERE clause to
876 * append to the SQL statement. Don't
877 * include the "WHERE" keyword.
879 * @return mixed a new DB_result object for successful SELECT queries
880 * or DB_OK for successul data manipulation queries.
881 * A DB_Error object on failure.
883 * @uses DB_common::autoPrepare(), DB_common::execute()
885 function autoExecute($table, $fields_values, $mode = DB_AUTOQUERY_INSERT,
889 $where = strtr($where, array('?' => '\?', '!' => '\!', '&' => '\&',));
891 $sth = $this->autoPrepare($table, array_keys($fields_values), $mode,
893 if (DB::isError($sth)) {
896 $ret = $this->execute($sth, array_values($fields_values));
897 $this->freePrepared($sth);
903 // {{{ buildManipSQL()
906 * Produces an SQL query string for autoPrepare()
910 * buildManipSQL('table_sql', array('field1', 'field2', 'field3'),
911 * DB_AUTOQUERY_INSERT);
916 * INSERT INTO table_sql (field1,field2,field3) VALUES (?,?,?)
920 * - This belongs more to a SQL Builder class, but this is a simple
922 * - Be carefull! If you don't give a $where param with an UPDATE
923 * query, all the records of the table will be updated!
925 * @param string $table the table name
926 * @param array $table_fields the array of field names
927 * @param int $mode a type of query to make:
928 * DB_AUTOQUERY_INSERT or DB_AUTOQUERY_UPDATE
929 * @param string $where for update queries: the WHERE clause to
930 * append to the SQL statement. Don't
931 * include the "WHERE" keyword.
933 * @return string the sql query for autoPrepare()
935 function buildManipSQL($table, $table_fields, $mode, $where = false)
937 if (count($table_fields) == 0) {
938 return $this->raiseError(DB_ERROR_NEED_MORE_DATA);
942 case DB_AUTOQUERY_INSERT:
945 foreach ($table_fields as $value) {
955 return "INSERT INTO $table ($names) VALUES ($values)";
956 case DB_AUTOQUERY_UPDATE:
958 foreach ($table_fields as $value) {
964 $set .= "$value = ?";
966 $sql = "UPDATE $table SET $set";
968 $sql .= " WHERE $where";
972 return $this->raiseError(DB_ERROR_SYNTAX);
980 * Executes a DB statement prepared with prepare()
984 * $sth = $db->prepare('INSERT INTO tbl (a, b, c) VALUES (?, !, &)');
990 * $res = $db->execute($sth, $data);
993 * @param resource $stmt a DB statement resource returned from prepare()
994 * @param mixed $data array, string or numeric data to be used in
995 * execution of the statement. Quantity of items
996 * passed must match quantity of placeholders in
997 * query: meaning 1 placeholder for non-array
998 * parameters or 1 placeholder per array element.
1000 * @return mixed a new DB_result object for successful SELECT queries
1001 * or DB_OK for successul data manipulation queries.
1002 * A DB_Error object on failure.
1004 * {@internal ibase and oci8 have their own execute() methods.}}
1006 * @see DB_common::prepare()
1008 function &execute($stmt, $data = array())
1010 $realquery = $this->executeEmulateQuery($stmt, $data);
1011 if (DB::isError($realquery)) {
1014 $result = $this->simpleQuery($realquery);
1016 if ($result === DB_OK || DB::isError($result)) {
1019 $tmp = new DB_result($this, $result);
1025 // {{{ executeEmulateQuery()
1028 * Emulates executing prepared statements if the DBMS not support them
1030 * @param resource $stmt a DB statement resource returned from execute()
1031 * @param mixed $data array, string or numeric data to be used in
1032 * execution of the statement. Quantity of items
1033 * passed must match quantity of placeholders in
1034 * query: meaning 1 placeholder for non-array
1035 * parameters or 1 placeholder per array element.
1037 * @return mixed a string containing the real query run when emulating
1038 * prepare/execute. A DB_Error object on failure.
1041 * @see DB_common::execute()
1043 function executeEmulateQuery($stmt, $data = array())
1046 $data = (array)$data;
1047 $this->last_parameters = $data;
1049 if (count($this->prepare_types[$stmt]) != count($data)) {
1050 $this->last_query = $this->prepared_queries[$stmt];
1051 return $this->raiseError(DB_ERROR_MISMATCH);
1054 $realquery = $this->prepare_tokens[$stmt][0];
1057 foreach ($data as $value) {
1058 if ($this->prepare_types[$stmt][$i] == DB_PARAM_SCALAR) {
1059 $realquery .= $this->quoteSmart($value);
1060 } elseif ($this->prepare_types[$stmt][$i] == DB_PARAM_OPAQUE) {
1061 $fp = @fopen($value, 'rb');
1063 return $this->raiseError(DB_ERROR_ACCESS_VIOLATION);
1065 $realquery .= $this->quoteSmart(fread($fp, filesize($value)));
1068 $realquery .= $value;
1071 $realquery .= $this->prepare_tokens[$stmt][++$i];
1078 // {{{ executeMultiple()
1081 * Performs several execute() calls on the same statement handle
1083 * $data must be an array indexed numerically
1084 * from 0, one execute call is done for every "row" in the array.
1086 * If an error occurs during execute(), executeMultiple() does not
1087 * execute the unfinished rows, but rather returns that error.
1089 * @param resource $stmt query handle from prepare()
1090 * @param array $data numeric array containing the
1091 * data to insert into the query
1093 * @return int DB_OK on success. A DB_Error object on failure.
1095 * @see DB_common::prepare(), DB_common::execute()
1097 function executeMultiple($stmt, $data)
1099 foreach ($data as $value) {
1100 $res = $this->execute($stmt, $value);
1101 if (DB::isError($res)) {
1109 // {{{ freePrepared()
1112 * Frees the internal resources associated with a prepared query
1114 * @param resource $stmt the prepared statement's PHP resource
1115 * @param bool $free_resource should the PHP resource be freed too?
1116 * Use false if you need to get data
1117 * from the result set later.
1119 * @return bool TRUE on success, FALSE if $result is invalid
1121 * @see DB_common::prepare()
1123 function freePrepared($stmt, $free_resource = true)
1126 if (isset($this->prepare_tokens[$stmt])) {
1127 unset($this->prepare_tokens[$stmt]);
1128 unset($this->prepare_types[$stmt]);
1129 unset($this->prepared_queries[$stmt]);
1136 // {{{ modifyQuery()
1139 * Changes a query string for various DBMS specific reasons
1141 * It is defined here to ensure all drivers have this method available.
1143 * @param string $query the query string to modify
1145 * @return string the modified query string
1148 * @see DB_mysql::modifyQuery(), DB_oci8::modifyQuery(),
1149 * DB_sqlite::modifyQuery()
1151 function modifyQuery($query)
1157 // {{{ modifyLimitQuery()
1160 * Adds LIMIT clauses to a query string according to current DBMS standards
1162 * It is defined here to assure that all implementations
1163 * have this method defined.
1165 * @param string $query the query to modify
1166 * @param int $from the row to start to fetching (0 = the first row)
1167 * @param int $count the numbers of rows to fetch
1168 * @param mixed $params array, string or numeric data to be used in
1169 * execution of the statement. Quantity of items
1170 * passed must match quantity of placeholders in
1171 * query: meaning 1 placeholder for non-array
1172 * parameters or 1 placeholder per array element.
1174 * @return string the query string with LIMIT clauses added
1178 function modifyLimitQuery($query, $from, $count, $params = array())
1187 * Sends a query to the database server
1189 * The query string can be either a normal statement to be sent directly
1190 * to the server OR if <var>$params</var> are passed the query can have
1191 * placeholders and it will be passed through prepare() and execute().
1193 * @param string $query the SQL query or the statement to prepare
1194 * @param mixed $params array, string or numeric data to be used in
1195 * execution of the statement. Quantity of items
1196 * passed must match quantity of placeholders in
1197 * query: meaning 1 placeholder for non-array
1198 * parameters or 1 placeholder per array element.
1200 * @return mixed a new DB_result object for successful SELECT queries
1201 * or DB_OK for successul data manipulation queries.
1202 * A DB_Error object on failure.
1204 * @see DB_result, DB_common::prepare(), DB_common::execute()
1206 function &query($query, $params = array())
1208 $params = (array)$params;
1209 if (count($params)) {
1210 $sth = $this->prepare($query);
1211 if (DB::isError($sth)) {
1214 $ret = $this->execute($sth, $params);
1215 $this->freePrepared($sth, false);
1218 $this->last_parameters = array();
1219 $result = $this->simpleQuery($query);
1220 if ($result === DB_OK || DB::isError($result)) {
1223 $tmp = new DB_result($this, $result);
1233 * Generates and executes a LIMIT query
1235 * @param string $query the query
1236 * @param intr $from the row to start to fetching (0 = the first row)
1237 * @param int $count the numbers of rows to fetch
1238 * @param mixed $params array, string or numeric data to be used in
1239 * execution of the statement. Quantity of items
1240 * passed must match quantity of placeholders in
1241 * query: meaning 1 placeholder for non-array
1242 * parameters or 1 placeholder per array element.
1244 * @return mixed a new DB_result object for successful SELECT queries
1245 * or DB_OK for successul data manipulation queries.
1246 * A DB_Error object on failure.
1248 function &limitQuery($query, $from, $count, $params = array())
1250 $query = $this->modifyLimitQuery($query, $from, $count, $params);
1251 if (DB::isError($query)){
1254 $result = $this->query($query, $params);
1255 if (is_object($result) && is_a($result, 'DB_result')) {
1256 $result->setOption('limit_from', $from);
1257 $result->setOption('limit_count', $count);
1266 * Fetches the first column of the first row from a query result
1268 * Takes care of doing the query and freeing the results when finished.
1270 * @param string $query the SQL query
1271 * @param mixed $params array, string or numeric data to be used in
1272 * execution of the statement. Quantity of items
1273 * passed must match quantity of placeholders in
1274 * query: meaning 1 placeholder for non-array
1275 * parameters or 1 placeholder per array element.
1277 * @return mixed the returned value of the query.
1278 * A DB_Error object on failure.
1280 function &getOne($query, $params = array())
1282 $params = (array)$params;
1283 // modifyLimitQuery() would be nice here, but it causes BC issues
1284 if (sizeof($params) > 0) {
1285 $sth = $this->prepare($query);
1286 if (DB::isError($sth)) {
1289 $res = $this->execute($sth, $params);
1290 $this->freePrepared($sth);
1292 $res = $this->query($query);
1295 if (DB::isError($res)) {
1299 $err = $res->fetchInto($row, DB_FETCHMODE_ORDERED);
1302 if ($err !== DB_OK) {
1313 * Fetches the first row of data returned from a query result
1315 * Takes care of doing the query and freeing the results when finished.
1317 * @param string $query the SQL query
1318 * @param mixed $params array, string or numeric data to be used in
1319 * execution of the statement. Quantity of items
1320 * passed must match quantity of placeholders in
1321 * query: meaning 1 placeholder for non-array
1322 * parameters or 1 placeholder per array element.
1323 * @param int $fetchmode the fetch mode to use
1325 * @return array the first row of results as an array.
1326 * A DB_Error object on failure.
1328 function &getRow($query, $params = array(),
1329 $fetchmode = DB_FETCHMODE_DEFAULT)
1331 // compat check, the params and fetchmode parameters used to
1332 // have the opposite order
1333 if (!is_array($params)) {
1334 if (is_array($fetchmode)) {
1335 if ($params === null) {
1336 $tmp = DB_FETCHMODE_DEFAULT;
1340 $params = $fetchmode;
1342 } elseif ($params !== null) {
1343 $fetchmode = $params;
1347 // modifyLimitQuery() would be nice here, but it causes BC issues
1348 $params = (array)$params;
1349 if (count($params)) {
1350 $sth = $this->prepare($query);
1351 if (DB::isError($sth)) {
1354 $res = $this->execute($sth, $params);
1355 $this->freePrepared($sth);
1357 $res = $this->query($query);
1360 if (DB::isError($res)) {
1364 $err = $res->fetchInto($row, $fetchmode);
1368 if ($err !== DB_OK) {
1379 * Fetches a single column from a query result and returns it as an
1382 * @param string $query the SQL query
1383 * @param mixed $col which column to return (integer [column number,
1384 * starting at 0] or string [column name])
1385 * @param mixed $params array, string or numeric data to be used in
1386 * execution of the statement. Quantity of items
1387 * passed must match quantity of placeholders in
1388 * query: meaning 1 placeholder for non-array
1389 * parameters or 1 placeholder per array element.
1391 * @return array the results as an array. A DB_Error object on failure.
1393 * @see DB_common::query()
1395 function &getCol($query, $col = 0, $params = array())
1397 $params = (array)$params;
1398 if (sizeof($params) > 0) {
1399 $sth = $this->prepare($query);
1401 if (DB::isError($sth)) {
1405 $res = $this->execute($sth, $params);
1406 $this->freePrepared($sth);
1408 $res = $this->query($query);
1411 if (DB::isError($res)) {
1415 $fetchmode = is_int($col) ? DB_FETCHMODE_ORDERED : DB_FETCHMODE_ASSOC;
1417 if (!is_array($row = $res->fetchRow($fetchmode))) {
1420 if (!array_key_exists($col, $row)) {
1421 $ret = $this->raiseError(DB_ERROR_NOSUCHFIELD);
1423 $ret = array($row[$col]);
1424 while (is_array($row = $res->fetchRow($fetchmode))) {
1425 $ret[] = $row[$col];
1432 if (DB::isError($row)) {
1443 * Fetches an entire query result and returns it as an
1444 * associative array using the first column as the key
1446 * If the result set contains more than two columns, the value
1447 * will be an array of the values from column 2-n. If the result
1448 * set contains only two columns, the returned value will be a
1449 * scalar with the value of the second column (unless forced to an
1450 * array with the $force_array parameter). A DB error code is
1451 * returned on errors. If the result set contains fewer than two
1452 * columns, a DB_ERROR_TRUNCATED error is returned.
1454 * For example, if the table "mytable" contains:
1458 * --------------------------------
1461 * 3 'three' 944679408
1464 * Then the call getAssoc('SELECT id,text FROM mytable') returns:
1473 * ...while the call getAssoc('SELECT id,text,date FROM mytable') returns:
1476 * '1' => array('one', '944679408'),
1477 * '2' => array('two', '944679408'),
1478 * '3' => array('three', '944679408')
1482 * If the more than one row occurs with the same value in the
1483 * first column, the last row overwrites all previous ones by
1484 * default. Use the $group parameter if you don't want to
1485 * overwrite like this. Example:
1488 * getAssoc('SELECT category,id,name FROM mytable', false, null,
1489 * DB_FETCHMODE_ASSOC, true) returns:
1492 * '1' => array(array('id' => '4', 'name' => 'number four'),
1493 * array('id' => '6', 'name' => 'number six')
1495 * '9' => array(array('id' => '4', 'name' => 'number four'),
1496 * array('id' => '6', 'name' => 'number six')
1501 * Keep in mind that database functions in PHP usually return string
1502 * values for results regardless of the database's internal type.
1504 * @param string $query the SQL query
1505 * @param bool $force_array used only when the query returns
1506 * exactly two columns. If true, the values
1507 * of the returned array will be one-element
1508 * arrays instead of scalars.
1509 * @param mixed $params array, string or numeric data to be used in
1510 * execution of the statement. Quantity of
1511 * items passed must match quantity of
1512 * placeholders in query: meaning 1
1513 * placeholder for non-array parameters or
1514 * 1 placeholder per array element.
1515 * @param int $fetchmode the fetch mode to use
1516 * @param bool $group if true, the values of the returned array
1517 * is wrapped in another array. If the same
1518 * key value (in the first column) repeats
1519 * itself, the values will be appended to
1520 * this array instead of overwriting the
1523 * @return array the associative array containing the query results.
1524 * A DB_Error object on failure.
1526 function &getAssoc($query, $force_array = false, $params = array(),
1527 $fetchmode = DB_FETCHMODE_DEFAULT, $group = false)
1529 $params = (array)$params;
1530 if (sizeof($params) > 0) {
1531 $sth = $this->prepare($query);
1533 if (DB::isError($sth)) {
1537 $res = $this->execute($sth, $params);
1538 $this->freePrepared($sth);
1540 $res = $this->query($query);
1543 if (DB::isError($res)) {
1546 if ($fetchmode == DB_FETCHMODE_DEFAULT) {
1547 $fetchmode = $this->fetchmode;
1549 $cols = $res->numCols();
1552 $tmp = $this->raiseError(DB_ERROR_TRUNCATED);
1558 if ($cols > 2 || $force_array) {
1559 // return array values
1560 // XXX this part can be optimized
1561 if ($fetchmode == DB_FETCHMODE_ASSOC) {
1562 while (is_array($row = $res->fetchRow(DB_FETCHMODE_ASSOC))) {
1564 $key = current($row);
1565 unset($row[key($row)]);
1567 $results[$key][] = $row;
1569 $results[$key] = $row;
1572 } elseif ($fetchmode == DB_FETCHMODE_OBJECT) {
1573 while ($row = $res->fetchRow(DB_FETCHMODE_OBJECT)) {
1574 $arr = get_object_vars($row);
1575 $key = current($arr);
1577 $results[$key][] = $row;
1579 $results[$key] = $row;
1583 while (is_array($row = $res->fetchRow(DB_FETCHMODE_ORDERED))) {
1584 // we shift away the first element to get
1585 // indices running from 0 again
1586 $key = array_shift($row);
1588 $results[$key][] = $row;
1590 $results[$key] = $row;
1594 if (DB::isError($row)) {
1598 // return scalar values
1599 while (is_array($row = $res->fetchRow(DB_FETCHMODE_ORDERED))) {
1601 $results[$row[0]][] = $row[1];
1603 $results[$row[0]] = $row[1];
1606 if (DB::isError($row)) {
1620 * Fetches all of the rows from a query result
1622 * @param string $query the SQL query
1623 * @param mixed $params array, string or numeric data to be used in
1624 * execution of the statement. Quantity of
1625 * items passed must match quantity of
1626 * placeholders in query: meaning 1
1627 * placeholder for non-array parameters or
1628 * 1 placeholder per array element.
1629 * @param int $fetchmode the fetch mode to use:
1630 * + DB_FETCHMODE_ORDERED
1631 * + DB_FETCHMODE_ASSOC
1632 * + DB_FETCHMODE_ORDERED | DB_FETCHMODE_FLIPPED
1633 * + DB_FETCHMODE_ASSOC | DB_FETCHMODE_FLIPPED
1635 * @return array the nested array. A DB_Error object on failure.
1637 function &getAll($query, $params = array(),
1638 $fetchmode = DB_FETCHMODE_DEFAULT)
1640 // compat check, the params and fetchmode parameters used to
1641 // have the opposite order
1642 if (!is_array($params)) {
1643 if (is_array($fetchmode)) {
1644 if ($params === null) {
1645 $tmp = DB_FETCHMODE_DEFAULT;
1649 $params = $fetchmode;
1651 } elseif ($params !== null) {
1652 $fetchmode = $params;
1657 $params = (array)$params;
1658 if (count($params)) {
1659 $sth = $this->prepare($query);
1661 if (DB::isError($sth)) {
1665 $res = $this->execute($sth, $params);
1666 $this->freePrepared($sth);
1668 $res = $this->query($query);
1671 if ($res === DB_OK || DB::isError($res)) {
1676 while (DB_OK === $res->fetchInto($row, $fetchmode)) {
1677 if ($fetchmode & DB_FETCHMODE_FLIPPED) {
1678 foreach ($row as $key => $val) {
1679 $results[$key][] = $val;
1688 if (DB::isError($row)) {
1689 $tmp = $this->raiseError($row);
1699 * Enables or disables automatic commits
1701 * @param bool $onoff true turns it on, false turns it off
1703 * @return int DB_OK on success. A DB_Error object if the driver
1704 * doesn't support auto-committing transactions.
1706 function autoCommit($onoff = false)
1708 return $this->raiseError(DB_ERROR_NOT_CAPABLE);
1715 * Commits the current transaction
1717 * @return int DB_OK on success. A DB_Error object on failure.
1721 return $this->raiseError(DB_ERROR_NOT_CAPABLE);
1728 * Reverts the current transaction
1730 * @return int DB_OK on success. A DB_Error object on failure.
1734 return $this->raiseError(DB_ERROR_NOT_CAPABLE);
1741 * Determines the number of rows in a query result
1743 * @param resource $result the query result idenifier produced by PHP
1745 * @return int the number of rows. A DB_Error object on failure.
1747 function numRows($result)
1749 return $this->raiseError(DB_ERROR_NOT_CAPABLE);
1753 // {{{ affectedRows()
1756 * Determines the number of rows affected by a data maniuplation query
1758 * 0 is returned for queries that don't manipulate data.
1760 * @return int the number of rows. A DB_Error object on failure.
1762 function affectedRows()
1764 return $this->raiseError(DB_ERROR_NOT_CAPABLE);
1768 // {{{ getSequenceName()
1771 * Generates the name used inside the database for a sequence
1773 * The createSequence() docblock contains notes about storing sequence
1776 * @param string $sqn the sequence's public name
1778 * @return string the sequence's name in the backend
1781 * @see DB_common::createSequence(), DB_common::dropSequence(),
1782 * DB_common::nextID(), DB_common::setOption()
1784 function getSequenceName($sqn)
1786 return sprintf($this->getOption('seqname_format'),
1787 preg_replace('/[^a-z0-9_.]/i', '_', $sqn));
1794 * Returns the next free id in a sequence
1796 * @param string $seq_name name of the sequence
1797 * @param boolean $ondemand when true, the seqence is automatically
1798 * created if it does not exist
1800 * @return int the next id number in the sequence.
1801 * A DB_Error object on failure.
1803 * @see DB_common::createSequence(), DB_common::dropSequence(),
1804 * DB_common::getSequenceName()
1806 function nextId($seq_name, $ondemand = true)
1808 return $this->raiseError(DB_ERROR_NOT_CAPABLE);
1812 // {{{ createSequence()
1815 * Creates a new sequence
1817 * The name of a given sequence is determined by passing the string
1818 * provided in the <var>$seq_name</var> argument through PHP's sprintf()
1819 * function using the value from the <var>seqname_format</var> option as
1820 * the sprintf()'s format argument.
1822 * <var>seqname_format</var> is set via setOption().
1824 * @param string $seq_name name of the new sequence
1826 * @return int DB_OK on success. A DB_Error object on failure.
1828 * @see DB_common::dropSequence(), DB_common::getSequenceName(),
1829 * DB_common::nextID()
1831 function createSequence($seq_name)
1833 return $this->raiseError(DB_ERROR_NOT_CAPABLE);
1837 // {{{ dropSequence()
1840 * Deletes a sequence
1842 * @param string $seq_name name of the sequence to be deleted
1844 * @return int DB_OK on success. A DB_Error object on failure.
1846 * @see DB_common::createSequence(), DB_common::getSequenceName(),
1847 * DB_common::nextID()
1849 function dropSequence($seq_name)
1851 return $this->raiseError(DB_ERROR_NOT_CAPABLE);
1858 * Communicates an error and invoke error callbacks, etc
1860 * Basically a wrapper for PEAR::raiseError without the message string.
1862 * @param mixed integer error code, or a PEAR error object (all
1863 * other parameters are ignored if this parameter is
1865 * @param int error mode, see PEAR_Error docs
1866 * @param mixed if error mode is PEAR_ERROR_TRIGGER, this is the
1867 * error level (E_USER_NOTICE etc). If error mode is
1868 * PEAR_ERROR_CALLBACK, this is the callback function,
1869 * either as a function name, or as an array of an
1870 * object and method name. For other error modes this
1871 * parameter is ignored.
1872 * @param string extra debug information. Defaults to the last
1873 * query and native error code.
1874 * @param mixed native error code, integer or string depending the
1876 * @param mixed dummy parameter for E_STRICT compatibility with
1878 * @param mixed dummy parameter for E_STRICT compatibility with
1881 * @return object the PEAR_Error object
1885 function &raiseError($code = DB_ERROR, $mode = null, $options = null,
1886 $userinfo = null, $nativecode = null, $dummy1 = null,
1889 // The error is yet a DB error object
1890 if (is_object($code)) {
1891 // because we the static PEAR::raiseError, our global
1892 // handler should be used if it is set
1893 if ($mode === null && !empty($this->_default_error_mode)) {
1894 $mode = $this->_default_error_mode;
1895 $options = $this->_default_error_options;
1897 $tmp = PEAR::raiseError($code, null, $mode, $options,
1902 if ($userinfo === null) {
1903 $userinfo = $this->last_query;
1907 $userinfo .= ' [nativecode=' . trim($nativecode) . ']';
1909 $userinfo .= ' [DB Error: ' . DB::errorMessage($code) . ']';
1912 $tmp = PEAR::raiseError(null, $code, $mode, $options, $userinfo,
1918 // {{{ errorNative()
1921 * Gets the DBMS' native error code produced by the last query
1923 * @return mixed the DBMS' error code. A DB_Error object on failure.
1925 function errorNative()
1927 return $this->raiseError(DB_ERROR_NOT_CAPABLE);
1934 * Maps native error codes to DB's portable ones
1936 * Uses the <var>$errorcode_map</var> property defined in each driver.
1938 * @param string|int $nativecode the error code returned by the DBMS
1940 * @return int the portable DB error code. Return DB_ERROR if the
1941 * current driver doesn't have a mapping for the
1942 * $nativecode submitted.
1944 function errorCode($nativecode)
1946 if (isset($this->errorcode_map[$nativecode])) {
1947 return $this->errorcode_map[$nativecode];
1949 // Fall back to DB_ERROR if there was no mapping.
1954 // {{{ errorMessage()
1957 * Maps a DB error code to a textual message
1959 * @param integer $dbcode the DB error code
1961 * @return string the error message corresponding to the error code
1962 * submitted. FALSE if the error code is unknown.
1964 * @see DB::errorMessage()
1966 function errorMessage($dbcode)
1968 return DB::errorMessage($this->errorcode_map[$dbcode]);
1975 * Returns information about a table or a result set
1977 * The format of the resulting array depends on which <var>$mode</var>
1978 * you select. The sample output below is based on this query:
1980 * SELECT tblFoo.fldID, tblFoo.fldPhone, tblBar.fldId
1982 * JOIN tblBar ON tblFoo.fldId = tblBar.fldId
1988 * <kbd>null</kbd> (default)
1995 * [flags] => primary_key not_null
1999 * [name] => fldPhone
2009 * [flags] => primary_key not_null
2015 * <kbd>DB_TABLEINFO_ORDER</kbd>
2017 * <p>In addition to the information found in the default output,
2018 * a notation of the number of columns is provided by the
2019 * <samp>num_fields</samp> element while the <samp>order</samp>
2020 * element provides an array with the column names as the keys and
2021 * their location index number (corresponding to the keys in the
2022 * the default output) as the values.</p>
2024 * <p>If a result set has identical field names, the last one is
2029 * [order] => Array (
2037 * <kbd>DB_TABLEINFO_ORDERTABLE</kbd>
2039 * <p>Similar to <kbd>DB_TABLEINFO_ORDER</kbd> but adds more
2040 * dimensions to the array in which the table names are keys and
2041 * the field names are sub-keys. This is helpful for queries that
2042 * join tables which have identical field names.</p>
2046 * [ordertable] => Array (
2047 * [tblFoo] => Array (
2051 * [tblBar] => Array (
2060 * The <samp>flags</samp> element contains a space separated list
2061 * of extra information about the field. This data is inconsistent
2062 * between DBMS's due to the way each DBMS works.
2063 * + <samp>primary_key</samp>
2064 * + <samp>unique_key</samp>
2065 * + <samp>multiple_key</samp>
2066 * + <samp>not_null</samp>
2068 * Most DBMS's only provide the <samp>table</samp> and <samp>flags</samp>
2069 * elements if <var>$result</var> is a table name. The following DBMS's
2070 * provide full information from queries:
2074 * If the 'portability' option has <samp>DB_PORTABILITY_LOWERCASE</samp>
2075 * turned on, the names of tables and fields will be lowercased.
2077 * @param object|string $result DB_result object from a query or a
2078 * string containing the name of a table.
2079 * While this also accepts a query result
2080 * resource identifier, this behavior is
2082 * @param int $mode either unused or one of the tableInfo modes:
2083 * <kbd>DB_TABLEINFO_ORDERTABLE</kbd>,
2084 * <kbd>DB_TABLEINFO_ORDER</kbd> or
2085 * <kbd>DB_TABLEINFO_FULL</kbd> (which does both).
2086 * These are bitwise, so the first two can be
2087 * combined using <kbd>|</kbd>.
2089 * @return array an associative array with the information requested.
2090 * A DB_Error object on failure.
2092 * @see DB_common::setOption()
2094 function tableInfo($result, $mode = null)
2097 * If the DB_<driver> class has a tableInfo() method, that one
2098 * overrides this one. But, if the driver doesn't have one,
2099 * this method runs and tells users about that fact.
2101 return $this->raiseError(DB_ERROR_NOT_CAPABLE);
2108 * Lists the tables in the current database
2110 * @return array the list of tables. A DB_Error object on failure.
2112 * @deprecated Method deprecated some time before Release 1.2
2114 function getTables()
2116 return $this->getListOf('tables');
2123 * Lists internal database information
2125 * @param string $type type of information being sought.
2126 * Common items being sought are:
2127 * tables, databases, users, views, functions
2128 * Each DBMS's has its own capabilities.
2130 * @return array an array listing the items sought.
2131 * A DB DB_Error object on failure.
2133 function getListOf($type)
2135 $sql = $this->getSpecialQuery($type);
2136 if ($sql === null) {
2137 $this->last_query = '';
2138 return $this->raiseError(DB_ERROR_UNSUPPORTED);
2139 } elseif (is_int($sql) || DB::isError($sql)) {
2141 return $this->raiseError($sql);
2142 } elseif (is_array($sql)) {
2143 // Already the result
2146 // Launch this query
2147 return $this->getCol($sql);
2151 // {{{ getSpecialQuery()
2154 * Obtains the query string needed for listing a given type of objects
2156 * @param string $type the kind of objects you want to retrieve
2158 * @return string the SQL query string or null if the driver doesn't
2159 * support the object type requested
2162 * @see DB_common::getListOf()
2164 function getSpecialQuery($type)
2166 return $this->raiseError(DB_ERROR_UNSUPPORTED);
2170 // {{{ nextQueryIsManip()
2173 * Sets (or unsets) a flag indicating that the next query will be a
2174 * manipulation query, regardless of the usual DB::isManip() heuristics.
2176 * @param boolean true to set the flag overriding the isManip() behaviour,
2177 * false to clear it and fall back onto isManip()
2183 function nextQueryIsManip($manip)
2185 $this->_next_query_manip = $manip;
2189 // {{{ _checkManip()
2192 * Checks if the given query is a manipulation query. This also takes into
2193 * account the _next_query_manip flag and sets the _last_query_manip flag
2194 * (and resets _next_query_manip) according to the result.
2196 * @param string The query to check.
2198 * @return boolean true if the query is a manipulation query, false
2203 function _checkManip($query)
2205 if ($this->_next_query_manip || DB::isManip($query)) {
2206 $this->_last_query_manip = true;
2208 $this->_last_query_manip = false;
2210 $this->_next_query_manip = false;
2211 return $this->_last_query_manip;
2212 $manip = $this->_next_query_manip;
2216 // {{{ _rtrimArrayValues()
2219 * Right-trims all strings in an array
2221 * @param array $array the array to be trimmed (passed by reference)
2227 function _rtrimArrayValues(&$array)
2229 foreach ($array as $key => $value) {
2230 if (is_string($value)) {
2231 $array[$key] = rtrim($value);
2237 // {{{ _convertNullArrayValuesToEmpty()
2240 * Converts all null values in an array to empty strings
2242 * @param array $array the array to be de-nullified (passed by reference)
2248 function _convertNullArrayValuesToEmpty(&$array)
2250 foreach ($array as $key => $value) {
2251 if (is_null($value)) {