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-2005 The PHP Group
22 * @license http://www.php.net/license/3_0.txt PHP License 3.0
23 * @version CVS: $Id: common.php 12 2005-10-02 11:36:35Z sparc $
24 * @link http://pear.php.net/package/DB
28 * Obtain the PEAR class so it can be extended from
30 require_once '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-2005 The PHP Group
44 * @license http://www.php.net/license/3_0.txt PHP License 3.0
45 * @version Release: @package_version@
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();
129 * This constructor calls <kbd>$this->PEAR('DB_Error')</kbd>
135 $this->PEAR('DB_Error');
142 * Automatically indicates which properties should be saved
143 * when PHP's serialize() function is called
145 * @return array the array of properties names that should be saved
149 if ($this->connection) {
150 // Don't disconnect(), people use serialize() for many reasons
151 $this->was_connected = true;
153 $this->was_connected = false;
155 if (isset($this->autocommit)) {
156 return array('autocommit',
161 'fetchmode_object_class',
166 return array('dbsyntax',
170 'fetchmode_object_class',
181 * Automatically reconnects to the database when PHP's unserialize()
184 * The reconnection attempt is only performed if the object was connected
185 * at the time PHP's serialize() function was run.
191 if ($this->was_connected) {
192 $this->connect($this->dsn, $this->options);
200 * Automatic string conversion for PHP 5
202 * @return string a string describing the current PEAR DB object
204 * @since Method available since Release 1.7.0
206 function __toString()
208 $info = strtolower(get_class($this));
209 $info .= ': (phptype=' . $this->phptype .
210 ', dbsyntax=' . $this->dbsyntax .
212 if ($this->connection) {
213 $info .= ' [connected]';
222 * DEPRECATED: String conversion method
224 * @return string a string describing the current PEAR DB object
226 * @deprecated Method deprecated in Release 1.7.0
230 return $this->__toString();
237 * DEPRECATED: Quotes a string so it can be safely used within string
238 * delimiters in a query
240 * @param string $string the string to be quoted
242 * @return string the quoted string
244 * @see DB_common::quoteSmart(), DB_common::escapeSimple()
245 * @deprecated Method deprecated some time before Release 1.2
247 function quoteString($string)
249 $string = $this->quote($string);
250 if ($string{0} == "'") {
251 return substr($string, 1, -1);
260 * DEPRECATED: Quotes a string so it can be safely used in a query
262 * @param string $string the string to quote
264 * @return string the quoted string or the string <samp>NULL</samp>
265 * if the value submitted is <kbd>null</kbd>.
267 * @see DB_common::quoteSmart(), DB_common::escapeSimple()
268 * @deprecated Deprecated in release 1.6.0
270 function quote($string = null)
272 return ($string === null) ? 'NULL'
273 : "'" . str_replace("'", "''", $string) . "'";
277 // {{{ quoteIdentifier()
280 * Quotes a string so it can be safely used as a table or column name
282 * Delimiting style depends on which database driver is being used.
284 * NOTE: just because you CAN use delimited identifiers doesn't mean
285 * you SHOULD use them. In general, they end up causing way more
286 * problems than they solve.
288 * Portability is broken by using the following characters inside
289 * delimited identifiers:
290 * + backtick (<kbd>`</kbd>) -- due to MySQL
291 * + double quote (<kbd>"</kbd>) -- due to Oracle
292 * + brackets (<kbd>[</kbd> or <kbd>]</kbd>) -- due to Access
294 * Delimited identifiers are known to generally work correctly under
295 * the following drivers:
304 * + sybase (must execute <kbd>set quoted_identifier on</kbd> sometime
307 * InterBase doesn't seem to be able to use delimited identifiers
308 * via PHP 4. They work fine under PHP 5.
310 * @param string $str the identifier name to be quoted
312 * @return string the quoted identifier
314 * @since Method available since Release 1.6.0
316 function quoteIdentifier($str)
318 return '"' . str_replace('"', '""', $str) . '"';
325 * Formats input so it can be safely used in a query
327 * The output depends on the PHP data type of input and the database
330 * @param mixed $in the data to be formatted
332 * @return mixed the formatted data. The format depends on the input's
336 * <kbd>input</kbd> -> <samp>returns</samp>
339 * <kbd>null</kbd> -> the string <samp>NULL</samp>
342 * <kbd>integer</kbd> or <kbd>double</kbd> -> the unquoted number
345 * <kbd>bool</kbd> -> output depends on the driver in use
346 * Most drivers return integers: <samp>1</samp> if
347 * <kbd>true</kbd> or <samp>0</samp> if
349 * Some return strings: <samp>TRUE</samp> if
350 * <kbd>true</kbd> or <samp>FALSE</samp> if
352 * Finally one returns strings: <samp>T</samp> if
353 * <kbd>true</kbd> or <samp>F</samp> if
354 * <kbd>false</kbd>. Here is a list of each DBMS,
355 * the values returned and the suggested column type:
358 * <kbd>dbase</kbd> -> <samp>T/F</samp>
359 * (<kbd>Logical</kbd>)
362 * <kbd>fbase</kbd> -> <samp>TRUE/FALSE</samp>
363 * (<kbd>BOOLEAN</kbd>)
366 * <kbd>ibase</kbd> -> <samp>1/0</samp>
367 * (<kbd>SMALLINT</kbd>) [1]
370 * <kbd>ifx</kbd> -> <samp>1/0</samp>
371 * (<kbd>SMALLINT</kbd>) [1]
374 * <kbd>msql</kbd> -> <samp>1/0</samp>
375 * (<kbd>INTEGER</kbd>)
378 * <kbd>mssql</kbd> -> <samp>1/0</samp>
382 * <kbd>mysql</kbd> -> <samp>1/0</samp>
383 * (<kbd>TINYINT(1)</kbd>)
386 * <kbd>mysqli</kbd> -> <samp>1/0</samp>
387 * (<kbd>TINYINT(1)</kbd>)
390 * <kbd>oci8</kbd> -> <samp>1/0</samp>
391 * (<kbd>NUMBER(1)</kbd>)
394 * <kbd>odbc</kbd> -> <samp>1/0</samp>
395 * (<kbd>SMALLINT</kbd>) [1]
398 * <kbd>pgsql</kbd> -> <samp>TRUE/FALSE</samp>
399 * (<kbd>BOOLEAN</kbd>)
402 * <kbd>sqlite</kbd> -> <samp>1/0</samp>
403 * (<kbd>INTEGER</kbd>)
406 * <kbd>sybase</kbd> -> <samp>1/0</samp>
407 * (<kbd>TINYINT(1)</kbd>)
410 * [1] Accommodate the lowest common denominator because not all
411 * versions of have <kbd>BOOLEAN</kbd>.
414 * other (including strings and numeric strings) ->
415 * the data with single quotes escaped by preceeding
416 * single quotes, backslashes are escaped by preceeding
417 * backslashes, then the whole string is encapsulated
418 * between single quotes
422 * @see DB_common::escapeSimple()
423 * @since Method available since Release 1.6.0
425 function quoteSmart($in)
427 if (is_int($in) || is_double($in)) {
429 } elseif (is_bool($in)) {
431 } elseif (is_null($in)) {
434 return "'" . $this->escapeSimple($in) . "'";
439 // {{{ escapeSimple()
442 * Escapes a string according to the current DBMS's standards
444 * In SQLite, this makes things safe for inserts/updates, but may
445 * cause problems when performing text comparisons against columns
446 * containing binary data. See the
447 * {@link http://php.net/sqlite_escape_string PHP manual} for more info.
449 * @param string $str the string to be escaped
451 * @return string the escaped string
453 * @see DB_common::quoteSmart()
454 * @since Method available since Release 1.6.0
456 function escapeSimple($str)
458 return str_replace("'", "''", $str);
465 * Tells whether the present driver supports a given feature
467 * @param string $feature the feature you're curious about
469 * @return bool whether this driver supports $feature
471 function provides($feature)
473 return $this->features[$feature];
477 // {{{ setFetchMode()
480 * Sets the fetch mode that should be used by default for query results
482 * @param integer $fetchmode DB_FETCHMODE_ORDERED, DB_FETCHMODE_ASSOC
483 * or DB_FETCHMODE_OBJECT
484 * @param string $object_class the class name of the object to be returned
485 * by the fetch methods when the
486 * DB_FETCHMODE_OBJECT mode is selected.
487 * If no class is specified by default a cast
488 * to object from the assoc array row will be
489 * done. There is also the posibility to use
490 * and extend the 'DB_row' class.
492 * @see DB_FETCHMODE_ORDERED, DB_FETCHMODE_ASSOC, DB_FETCHMODE_OBJECT
494 function setFetchMode($fetchmode, $object_class = 'stdClass')
496 switch ($fetchmode) {
497 case DB_FETCHMODE_OBJECT:
498 $this->fetchmode_object_class = $object_class;
499 case DB_FETCHMODE_ORDERED:
500 case DB_FETCHMODE_ASSOC:
501 $this->fetchmode = $fetchmode;
504 return $this->raiseError('invalid fetchmode mode');
512 * Sets run-time configuration options for PEAR DB
514 * Options, their data types, default values and description:
517 * <var>autofree</var> <kbd>boolean</kbd> = <samp>false</samp>
518 * <br />should results be freed automatically when there are no
521 * <var>result_buffering</var> <kbd>integer</kbd> = <samp>500</samp>
522 * <br />how many rows of the result set should be buffered?
523 * <br />In mysql: mysql_unbuffered_query() is used instead of
524 * mysql_query() if this value is 0. (Release 1.7.0)
525 * <br />In oci8: this value is passed to ocisetprefetch().
528 * <var>debug</var> <kbd>integer</kbd> = <samp>0</samp>
531 * <var>persistent</var> <kbd>boolean</kbd> = <samp>false</samp>
532 * <br />should the connection be persistent?
534 * <var>portability</var> <kbd>integer</kbd> = <samp>DB_PORTABILITY_NONE</samp>
535 * <br />portability mode constant (see below)
537 * <var>seqname_format</var> <kbd>string</kbd> = <samp>%s_seq</samp>
538 * <br />the sprintf() format string used on sequence names. This
539 * format is applied to sequence names passed to
540 * createSequence(), nextID() and dropSequence().
542 * <var>ssl</var> <kbd>boolean</kbd> = <samp>false</samp>
543 * <br />use ssl to connect?
547 * -----------------------------------------
551 * These modes are bitwised, so they can be combined using <kbd>|</kbd>
552 * and removed using <kbd>^</kbd>. See the examples section below on how
555 * <samp>DB_PORTABILITY_NONE</samp>
556 * turn off all portability features
558 * This mode gets automatically turned on if the deprecated
559 * <var>optimize</var> option gets set to <samp>performance</samp>.
562 * <samp>DB_PORTABILITY_LOWERCASE</samp>
563 * convert names of tables and fields to lower case when using
564 * <kbd>get*()</kbd>, <kbd>fetch*()</kbd> and <kbd>tableInfo()</kbd>
566 * This mode gets automatically turned on in the following databases
567 * if the deprecated option <var>optimize</var> gets set to
568 * <samp>portability</samp>:
572 * <samp>DB_PORTABILITY_RTRIM</samp>
573 * right trim the data output by <kbd>get*()</kbd> <kbd>fetch*()</kbd>
576 * <samp>DB_PORTABILITY_DELETE_COUNT</samp>
577 * force reporting the number of rows deleted
579 * Some DBMS's don't count the number of rows deleted when performing
580 * simple <kbd>DELETE FROM tablename</kbd> queries. This portability
581 * mode tricks such DBMS's into telling the count by adding
582 * <samp>WHERE 1=1</samp> to the end of <kbd>DELETE</kbd> queries.
584 * This mode gets automatically turned on in the following databases
585 * if the deprecated option <var>optimize</var> gets set to
586 * <samp>portability</samp>:
593 * <samp>DB_PORTABILITY_NUMROWS</samp>
594 * enable hack that makes <kbd>numRows()</kbd> work in Oracle
596 * This mode gets automatically turned on in the following databases
597 * if the deprecated option <var>optimize</var> gets set to
598 * <samp>portability</samp>:
602 * <samp>DB_PORTABILITY_ERRORS</samp>
603 * makes certain error messages in certain drivers compatible
604 * with those from other DBMS's
606 * + mysql, mysqli: change unique/primary key constraints
607 * DB_ERROR_ALREADY_EXISTS -> DB_ERROR_CONSTRAINT
609 * + odbc(access): MS's ODBC driver reports 'no such field' as code
610 * 07001, which means 'too few parameters.' When this option is on
611 * that code gets mapped to DB_ERROR_NOSUCHFIELD.
612 * DB_ERROR_MISMATCH -> DB_ERROR_NOSUCHFIELD
614 * <samp>DB_PORTABILITY_NULL_TO_EMPTY</samp>
615 * convert null values to empty strings in data output by get*() and
616 * fetch*(). Needed because Oracle considers empty strings to be null,
617 * while most other DBMS's know the difference between empty and null.
620 * <samp>DB_PORTABILITY_ALL</samp>
621 * turn on all portability features
623 * -----------------------------------------
625 * Example 1. Simple setOption() example
627 * $db->setOption('autofree', true);
630 * Example 2. Portability for lowercasing and trimming
632 * $db->setOption('portability',
633 * DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_RTRIM);
636 * Example 3. All portability options except trimming
638 * $db->setOption('portability',
639 * DB_PORTABILITY_ALL ^ DB_PORTABILITY_RTRIM);
642 * @param string $option option name
643 * @param mixed $value value for the option
645 * @return int DB_OK on success. A DB_Error object on failure.
647 * @see DB_common::$options
649 function setOption($option, $value)
651 if (isset($this->options[$option])) {
652 $this->options[$option] = $value;
655 * Backwards compatibility check for the deprecated 'optimize'
656 * option. Done here in case settings change after connecting.
658 if ($option == 'optimize') {
659 if ($value == 'portability') {
660 switch ($this->phptype) {
662 $this->options['portability'] =
663 DB_PORTABILITY_LOWERCASE |
664 DB_PORTABILITY_NUMROWS;
670 $this->options['portability'] =
671 DB_PORTABILITY_DELETE_COUNT;
675 $this->options['portability'] = DB_PORTABILITY_NONE;
681 return $this->raiseError("unknown option $option");
688 * Returns the value of an option
690 * @param string $option the option name you're curious about
692 * @return mixed the option's value
694 function getOption($option)
696 if (isset($this->options[$option])) {
697 return $this->options[$option];
699 return $this->raiseError("unknown option $option");
706 * Prepares a query for multiple execution with execute()
708 * Creates a query that can be run multiple times. Each time it is run,
709 * the placeholders, if any, will be replaced by the contents of
710 * execute()'s $data argument.
712 * Three types of placeholders can be used:
713 * + <kbd>?</kbd> scalar value (i.e. strings, integers). The system
714 * will automatically quote and escape the data.
715 * + <kbd>!</kbd> value is inserted 'as is'
716 * + <kbd>&</kbd> requires a file name. The file's contents get
717 * inserted into the query (i.e. saving binary
722 * $sth = $db->prepare('INSERT INTO tbl (a, b, c) VALUES (?, !, &)');
728 * $res = $db->execute($sth, $data);
731 * Use backslashes to escape placeholder characters if you don't want
732 * them to be interpreted as placeholders:
734 * "UPDATE foo SET col=? WHERE col='over \& under'"
737 * With some database backends, this is emulated.
739 * {@internal ibase and oci8 have their own prepare() methods.}}
741 * @param string $query the query to be prepared
743 * @return mixed DB statement resource on success. A DB_Error object
746 * @see DB_common::execute()
748 function prepare($query)
750 $tokens = preg_split('/((?<!\\\)[&?!])/', $query, -1,
751 PREG_SPLIT_DELIM_CAPTURE);
754 $newtokens = array();
756 foreach ($tokens as $val) {
759 $types[$token++] = DB_PARAM_SCALAR;
762 $types[$token++] = DB_PARAM_OPAQUE;
765 $types[$token++] = DB_PARAM_MISC;
768 $newtokens[] = preg_replace('/\\\([&?!])/', "\\1", $val);
772 $this->prepare_tokens[] = &$newtokens;
773 end($this->prepare_tokens);
775 $k = key($this->prepare_tokens);
776 $this->prepare_types[$k] = $types;
777 $this->prepared_queries[$k] = implode(' ', $newtokens);
786 * Automaticaly generates an insert or update query and pass it to prepare()
788 * @param string $table the table name
789 * @param array $table_fields the array of field names
790 * @param int $mode a type of query to make:
791 * DB_AUTOQUERY_INSERT or DB_AUTOQUERY_UPDATE
792 * @param string $where for update queries: the WHERE clause to
793 * append to the SQL statement. Don't
794 * include the "WHERE" keyword.
796 * @return resource the query handle
798 * @uses DB_common::prepare(), DB_common::buildManipSQL()
800 function autoPrepare($table, $table_fields, $mode = DB_AUTOQUERY_INSERT,
803 $query = $this->buildManipSQL($table, $table_fields, $mode, $where);
804 if (DB::isError($query)) {
807 return $this->prepare($query);
814 * Automaticaly generates an insert or update query and call prepare()
815 * and execute() with it
817 * @param string $table the table name
818 * @param array $fields_values the associative array where $key is a
819 * field name and $value its value
820 * @param int $mode a type of query to make:
821 * DB_AUTOQUERY_INSERT or DB_AUTOQUERY_UPDATE
822 * @param string $where for update queries: the WHERE clause to
823 * append to the SQL statement. Don't
824 * include the "WHERE" keyword.
826 * @return mixed a new DB_result object for successful SELECT queries
827 * or DB_OK for successul data manipulation queries.
828 * A DB_Error object on failure.
830 * @uses DB_common::autoPrepare(), DB_common::execute()
832 function autoExecute($table, $fields_values, $mode = DB_AUTOQUERY_INSERT,
835 $sth = $this->autoPrepare($table, array_keys($fields_values), $mode,
837 if (DB::isError($sth)) {
840 $ret =& $this->execute($sth, array_values($fields_values));
841 $this->freePrepared($sth);
847 // {{{ buildManipSQL()
850 * Produces an SQL query string for autoPrepare()
854 * buildManipSQL('table_sql', array('field1', 'field2', 'field3'),
855 * DB_AUTOQUERY_INSERT);
860 * INSERT INTO table_sql (field1,field2,field3) VALUES (?,?,?)
864 * - This belongs more to a SQL Builder class, but this is a simple
866 * - Be carefull! If you don't give a $where param with an UPDATE
867 * query, all the records of the table will be updated!
869 * @param string $table the table name
870 * @param array $table_fields the array of field names
871 * @param int $mode a type of query to make:
872 * DB_AUTOQUERY_INSERT or DB_AUTOQUERY_UPDATE
873 * @param string $where for update queries: the WHERE clause to
874 * append to the SQL statement. Don't
875 * include the "WHERE" keyword.
877 * @return string the sql query for autoPrepare()
879 function buildManipSQL($table, $table_fields, $mode, $where = false)
881 if (count($table_fields) == 0) {
882 return $this->raiseError(DB_ERROR_NEED_MORE_DATA);
886 case DB_AUTOQUERY_INSERT:
889 foreach ($table_fields as $value) {
899 return "INSERT INTO $table ($names) VALUES ($values)";
900 case DB_AUTOQUERY_UPDATE:
902 foreach ($table_fields as $value) {
908 $set .= "$value = ?";
910 $sql = "UPDATE $table SET $set";
912 $sql .= " WHERE $where";
916 return $this->raiseError(DB_ERROR_SYNTAX);
924 * Executes a DB statement prepared with prepare()
928 * $sth = $db->prepare('INSERT INTO tbl (a, b, c) VALUES (?, !, &)');
934 * $res =& $db->execute($sth, $data);
937 * @param resource $stmt a DB statement resource returned from prepare()
938 * @param mixed $data array, string or numeric data to be used in
939 * execution of the statement. Quantity of items
940 * passed must match quantity of placeholders in
941 * query: meaning 1 placeholder for non-array
942 * parameters or 1 placeholder per array element.
944 * @return mixed a new DB_result object for successful SELECT queries
945 * or DB_OK for successul data manipulation queries.
946 * A DB_Error object on failure.
948 * {@internal ibase and oci8 have their own execute() methods.}}
950 * @see DB_common::prepare()
952 function &execute($stmt, $data = array())
954 $realquery = $this->executeEmulateQuery($stmt, $data);
955 if (DB::isError($realquery)) {
958 $result = $this->simpleQuery($realquery);
960 if ($result === DB_OK || DB::isError($result)) {
963 $tmp =& new DB_result($this, $result);
969 // {{{ executeEmulateQuery()
972 * Emulates executing prepared statements if the DBMS not support them
974 * @param resource $stmt a DB statement resource returned from execute()
975 * @param mixed $data array, string or numeric data to be used in
976 * execution of the statement. Quantity of items
977 * passed must match quantity of placeholders in
978 * query: meaning 1 placeholder for non-array
979 * parameters or 1 placeholder per array element.
981 * @return mixed a string containing the real query run when emulating
982 * prepare/execute. A DB_Error object on failure.
985 * @see DB_common::execute()
987 function executeEmulateQuery($stmt, $data = array())
990 $data = (array)$data;
991 $this->last_parameters = $data;
993 if (count($this->prepare_types[$stmt]) != count($data)) {
994 $this->last_query = $this->prepared_queries[$stmt];
995 return $this->raiseError(DB_ERROR_MISMATCH);
998 $realquery = $this->prepare_tokens[$stmt][0];
1001 foreach ($data as $value) {
1002 if ($this->prepare_types[$stmt][$i] == DB_PARAM_SCALAR) {
1003 $realquery .= $this->quoteSmart($value);
1004 } elseif ($this->prepare_types[$stmt][$i] == DB_PARAM_OPAQUE) {
1005 $fp = @fopen($value, 'rb');
1007 return $this->raiseError(DB_ERROR_ACCESS_VIOLATION);
1009 $realquery .= $this->quoteSmart(fread($fp, filesize($value)));
1012 $realquery .= $value;
1015 $realquery .= $this->prepare_tokens[$stmt][++$i];
1022 // {{{ executeMultiple()
1025 * Performs several execute() calls on the same statement handle
1027 * $data must be an array indexed numerically
1028 * from 0, one execute call is done for every "row" in the array.
1030 * If an error occurs during execute(), executeMultiple() does not
1031 * execute the unfinished rows, but rather returns that error.
1033 * @param resource $stmt query handle from prepare()
1034 * @param array $data numeric array containing the
1035 * data to insert into the query
1037 * @return int DB_OK on success. A DB_Error object on failure.
1039 * @see DB_common::prepare(), DB_common::execute()
1041 function executeMultiple($stmt, $data)
1043 foreach ($data as $value) {
1044 $res =& $this->execute($stmt, $value);
1045 if (DB::isError($res)) {
1053 // {{{ freePrepared()
1056 * Frees the internal resources associated with a prepared query
1058 * @param resource $stmt the prepared statement's PHP resource
1059 * @param bool $free_resource should the PHP resource be freed too?
1060 * Use false if you need to get data
1061 * from the result set later.
1063 * @return bool TRUE on success, FALSE if $result is invalid
1065 * @see DB_common::prepare()
1067 function freePrepared($stmt, $free_resource = true)
1070 if (isset($this->prepare_tokens[$stmt])) {
1071 unset($this->prepare_tokens[$stmt]);
1072 unset($this->prepare_types[$stmt]);
1073 unset($this->prepared_queries[$stmt]);
1080 // {{{ modifyQuery()
1083 * Changes a query string for various DBMS specific reasons
1085 * It is defined here to ensure all drivers have this method available.
1087 * @param string $query the query string to modify
1089 * @return string the modified query string
1092 * @see DB_mysql::modifyQuery(), DB_oci8::modifyQuery(),
1093 * DB_sqlite::modifyQuery()
1095 function modifyQuery($query)
1101 // {{{ modifyLimitQuery()
1104 * Adds LIMIT clauses to a query string according to current DBMS standards
1106 * It is defined here to assure that all implementations
1107 * have this method defined.
1109 * @param string $query the query to modify
1110 * @param int $from the row to start to fetching (0 = the first row)
1111 * @param int $count the numbers of rows to fetch
1112 * @param mixed $params array, string or numeric data to be used in
1113 * execution of the statement. Quantity of items
1114 * passed must match quantity of placeholders in
1115 * query: meaning 1 placeholder for non-array
1116 * parameters or 1 placeholder per array element.
1118 * @return string the query string with LIMIT clauses added
1122 function modifyLimitQuery($query, $from, $count, $params = array())
1131 * Sends a query to the database server
1133 * The query string can be either a normal statement to be sent directly
1134 * to the server OR if <var>$params</var> are passed the query can have
1135 * placeholders and it will be passed through prepare() and execute().
1137 * @param string $query the SQL query or the statement to prepare
1138 * @param mixed $params array, string or numeric data to be used in
1139 * execution of the statement. Quantity of items
1140 * passed must match quantity of placeholders in
1141 * query: meaning 1 placeholder for non-array
1142 * parameters or 1 placeholder per array element.
1144 * @return mixed a new DB_result object for successful SELECT queries
1145 * or DB_OK for successul data manipulation queries.
1146 * A DB_Error object on failure.
1148 * @see DB_result, DB_common::prepare(), DB_common::execute()
1150 function &query($query, $params = array())
1152 if (sizeof($params) > 0) {
1153 $sth = $this->prepare($query);
1154 if (DB::isError($sth)) {
1157 $ret =& $this->execute($sth, $params);
1158 $this->freePrepared($sth, false);
1161 $this->last_parameters = array();
1162 $result = $this->simpleQuery($query);
1163 if ($result === DB_OK || DB::isError($result)) {
1166 $tmp =& new DB_result($this, $result);
1176 * Generates and executes a LIMIT query
1178 * @param string $query the query
1179 * @param intr $from the row to start to fetching (0 = the first row)
1180 * @param int $count the numbers of rows to fetch
1181 * @param mixed $params array, string or numeric data to be used in
1182 * execution of the statement. Quantity of items
1183 * passed must match quantity of placeholders in
1184 * query: meaning 1 placeholder for non-array
1185 * parameters or 1 placeholder per array element.
1187 * @return mixed a new DB_result object for successful SELECT queries
1188 * or DB_OK for successul data manipulation queries.
1189 * A DB_Error object on failure.
1191 function &limitQuery($query, $from, $count, $params = array())
1193 $query = $this->modifyLimitQuery($query, $from, $count, $params);
1194 if (DB::isError($query)){
1197 $result =& $this->query($query, $params);
1198 if (is_a($result, 'DB_result')) {
1199 $result->setOption('limit_from', $from);
1200 $result->setOption('limit_count', $count);
1209 * Fetches the first column of the first row from a query result
1211 * Takes care of doing the query and freeing the results when finished.
1213 * @param string $query the SQL query
1214 * @param mixed $params array, string or numeric data to be used in
1215 * execution of the statement. Quantity of items
1216 * passed must match quantity of placeholders in
1217 * query: meaning 1 placeholder for non-array
1218 * parameters or 1 placeholder per array element.
1220 * @return mixed the returned value of the query.
1221 * A DB_Error object on failure.
1223 function &getOne($query, $params = array())
1225 $params = (array)$params;
1226 // modifyLimitQuery() would be nice here, but it causes BC issues
1227 if (sizeof($params) > 0) {
1228 $sth = $this->prepare($query);
1229 if (DB::isError($sth)) {
1232 $res =& $this->execute($sth, $params);
1233 $this->freePrepared($sth);
1235 $res =& $this->query($query);
1238 if (DB::isError($res)) {
1242 $err = $res->fetchInto($row, DB_FETCHMODE_ORDERED);
1245 if ($err !== DB_OK) {
1256 * Fetches the first row of data returned from a query result
1258 * Takes care of doing the query and freeing the results when finished.
1260 * @param string $query the SQL query
1261 * @param mixed $params array, string or numeric data to be used in
1262 * execution of the statement. Quantity of items
1263 * passed must match quantity of placeholders in
1264 * query: meaning 1 placeholder for non-array
1265 * parameters or 1 placeholder per array element.
1266 * @param int $fetchmode the fetch mode to use
1268 * @return array the first row of results as an array.
1269 * A DB_Error object on failure.
1271 function &getRow($query, $params = array(),
1272 $fetchmode = DB_FETCHMODE_DEFAULT)
1274 // compat check, the params and fetchmode parameters used to
1275 // have the opposite order
1276 if (!is_array($params)) {
1277 if (is_array($fetchmode)) {
1278 if ($params === null) {
1279 $tmp = DB_FETCHMODE_DEFAULT;
1283 $params = $fetchmode;
1285 } elseif ($params !== null) {
1286 $fetchmode = $params;
1290 // modifyLimitQuery() would be nice here, but it causes BC issues
1291 if (sizeof($params) > 0) {
1292 $sth = $this->prepare($query);
1293 if (DB::isError($sth)) {
1296 $res =& $this->execute($sth, $params);
1297 $this->freePrepared($sth);
1299 $res =& $this->query($query);
1302 if (DB::isError($res)) {
1306 $err = $res->fetchInto($row, $fetchmode);
1310 if ($err !== DB_OK) {
1321 * Fetches a single column from a query result and returns it as an
1324 * @param string $query the SQL query
1325 * @param mixed $col which column to return (integer [column number,
1326 * starting at 0] or string [column name])
1327 * @param mixed $params array, string or numeric data to be used in
1328 * execution of the statement. Quantity of items
1329 * passed must match quantity of placeholders in
1330 * query: meaning 1 placeholder for non-array
1331 * parameters or 1 placeholder per array element.
1333 * @return array the results as an array. A DB_Error object on failure.
1335 * @see DB_common::query()
1337 function &getCol($query, $col = 0, $params = array())
1339 $params = (array)$params;
1340 if (sizeof($params) > 0) {
1341 $sth = $this->prepare($query);
1343 if (DB::isError($sth)) {
1347 $res =& $this->execute($sth, $params);
1348 $this->freePrepared($sth);
1350 $res =& $this->query($query);
1353 if (DB::isError($res)) {
1357 $fetchmode = is_int($col) ? DB_FETCHMODE_ORDERED : DB_FETCHMODE_ASSOC;
1359 if (!is_array($row = $res->fetchRow($fetchmode))) {
1362 if (!array_key_exists($col, $row)) {
1363 $ret =& $this->raiseError(DB_ERROR_NOSUCHFIELD);
1365 $ret = array($row[$col]);
1366 while (is_array($row = $res->fetchRow($fetchmode))) {
1367 $ret[] = $row[$col];
1374 if (DB::isError($row)) {
1385 * Fetches an entire query result and returns it as an
1386 * associative array using the first column as the key
1388 * If the result set contains more than two columns, the value
1389 * will be an array of the values from column 2-n. If the result
1390 * set contains only two columns, the returned value will be a
1391 * scalar with the value of the second column (unless forced to an
1392 * array with the $force_array parameter). A DB error code is
1393 * returned on errors. If the result set contains fewer than two
1394 * columns, a DB_ERROR_TRUNCATED error is returned.
1396 * For example, if the table "mytable" contains:
1400 * --------------------------------
1403 * 3 'three' 944679408
1406 * Then the call getAssoc('SELECT id,text FROM mytable') returns:
1415 * ...while the call getAssoc('SELECT id,text,date FROM mytable') returns:
1418 * '1' => array('one', '944679408'),
1419 * '2' => array('two', '944679408'),
1420 * '3' => array('three', '944679408')
1424 * If the more than one row occurs with the same value in the
1425 * first column, the last row overwrites all previous ones by
1426 * default. Use the $group parameter if you don't want to
1427 * overwrite like this. Example:
1430 * getAssoc('SELECT category,id,name FROM mytable', false, null,
1431 * DB_FETCHMODE_ASSOC, true) returns:
1434 * '1' => array(array('id' => '4', 'name' => 'number four'),
1435 * array('id' => '6', 'name' => 'number six')
1437 * '9' => array(array('id' => '4', 'name' => 'number four'),
1438 * array('id' => '6', 'name' => 'number six')
1443 * Keep in mind that database functions in PHP usually return string
1444 * values for results regardless of the database's internal type.
1446 * @param string $query the SQL query
1447 * @param bool $force_array used only when the query returns
1448 * exactly two columns. If true, the values
1449 * of the returned array will be one-element
1450 * arrays instead of scalars.
1451 * @param mixed $params array, string or numeric data to be used in
1452 * execution of the statement. Quantity of
1453 * items passed must match quantity of
1454 * placeholders in query: meaning 1
1455 * placeholder for non-array parameters or
1456 * 1 placeholder per array element.
1457 * @param int $fetchmode the fetch mode to use
1458 * @param bool $group if true, the values of the returned array
1459 * is wrapped in another array. If the same
1460 * key value (in the first column) repeats
1461 * itself, the values will be appended to
1462 * this array instead of overwriting the
1465 * @return array the associative array containing the query results.
1466 * A DB_Error object on failure.
1468 function &getAssoc($query, $force_array = false, $params = array(),
1469 $fetchmode = DB_FETCHMODE_DEFAULT, $group = false)
1471 $params = (array)$params;
1472 if (sizeof($params) > 0) {
1473 $sth = $this->prepare($query);
1475 if (DB::isError($sth)) {
1479 $res =& $this->execute($sth, $params);
1480 $this->freePrepared($sth);
1482 $res =& $this->query($query);
1485 if (DB::isError($res)) {
1488 if ($fetchmode == DB_FETCHMODE_DEFAULT) {
1489 $fetchmode = $this->fetchmode;
1491 $cols = $res->numCols();
1494 $tmp =& $this->raiseError(DB_ERROR_TRUNCATED);
1500 if ($cols > 2 || $force_array) {
1501 // return array values
1502 // XXX this part can be optimized
1503 if ($fetchmode == DB_FETCHMODE_ASSOC) {
1504 while (is_array($row = $res->fetchRow(DB_FETCHMODE_ASSOC))) {
1506 $key = current($row);
1507 unset($row[key($row)]);
1509 $results[$key][] = $row;
1511 $results[$key] = $row;
1514 } elseif ($fetchmode == DB_FETCHMODE_OBJECT) {
1515 while ($row = $res->fetchRow(DB_FETCHMODE_OBJECT)) {
1516 $arr = get_object_vars($row);
1517 $key = current($arr);
1519 $results[$key][] = $row;
1521 $results[$key] = $row;
1525 while (is_array($row = $res->fetchRow(DB_FETCHMODE_ORDERED))) {
1526 // we shift away the first element to get
1527 // indices running from 0 again
1528 $key = array_shift($row);
1530 $results[$key][] = $row;
1532 $results[$key] = $row;
1536 if (DB::isError($row)) {
1540 // return scalar values
1541 while (is_array($row = $res->fetchRow(DB_FETCHMODE_ORDERED))) {
1543 $results[$row[0]][] = $row[1];
1545 $results[$row[0]] = $row[1];
1548 if (DB::isError($row)) {
1562 * Fetches all of the rows from a query result
1564 * @param string $query the SQL query
1565 * @param mixed $params array, string or numeric data to be used in
1566 * execution of the statement. Quantity of
1567 * items passed must match quantity of
1568 * placeholders in query: meaning 1
1569 * placeholder for non-array parameters or
1570 * 1 placeholder per array element.
1571 * @param int $fetchmode the fetch mode to use:
1572 * + DB_FETCHMODE_ORDERED
1573 * + DB_FETCHMODE_ASSOC
1574 * + DB_FETCHMODE_ORDERED | DB_FETCHMODE_FLIPPED
1575 * + DB_FETCHMODE_ASSOC | DB_FETCHMODE_FLIPPED
1577 * @return array the nested array. A DB_Error object on failure.
1579 function &getAll($query, $params = array(),
1580 $fetchmode = DB_FETCHMODE_DEFAULT)
1582 // compat check, the params and fetchmode parameters used to
1583 // have the opposite order
1584 if (!is_array($params)) {
1585 if (is_array($fetchmode)) {
1586 if ($params === null) {
1587 $tmp = DB_FETCHMODE_DEFAULT;
1591 $params = $fetchmode;
1593 } elseif ($params !== null) {
1594 $fetchmode = $params;
1599 if (sizeof($params) > 0) {
1600 $sth = $this->prepare($query);
1602 if (DB::isError($sth)) {
1606 $res =& $this->execute($sth, $params);
1607 $this->freePrepared($sth);
1609 $res =& $this->query($query);
1612 if ($res === DB_OK || DB::isError($res)) {
1617 while (DB_OK === $res->fetchInto($row, $fetchmode)) {
1618 if ($fetchmode & DB_FETCHMODE_FLIPPED) {
1619 foreach ($row as $key => $val) {
1620 $results[$key][] = $val;
1629 if (DB::isError($row)) {
1630 $tmp =& $this->raiseError($row);
1640 * Enables or disables automatic commits
1642 * @param bool $onoff true turns it on, false turns it off
1644 * @return int DB_OK on success. A DB_Error object if the driver
1645 * doesn't support auto-committing transactions.
1647 function autoCommit($onoff = false)
1649 return $this->raiseError(DB_ERROR_NOT_CAPABLE);
1656 * Commits the current transaction
1658 * @return int DB_OK on success. A DB_Error object on failure.
1662 return $this->raiseError(DB_ERROR_NOT_CAPABLE);
1669 * Reverts the current transaction
1671 * @return int DB_OK on success. A DB_Error object on failure.
1675 return $this->raiseError(DB_ERROR_NOT_CAPABLE);
1682 * Determines the number of rows in a query result
1684 * @param resource $result the query result idenifier produced by PHP
1686 * @return int the number of rows. A DB_Error object on failure.
1688 function numRows($result)
1690 return $this->raiseError(DB_ERROR_NOT_CAPABLE);
1694 // {{{ affectedRows()
1697 * Determines the number of rows affected by a data maniuplation query
1699 * 0 is returned for queries that don't manipulate data.
1701 * @return int the number of rows. A DB_Error object on failure.
1703 function affectedRows()
1705 return $this->raiseError(DB_ERROR_NOT_CAPABLE);
1709 // {{{ getSequenceName()
1712 * Generates the name used inside the database for a sequence
1714 * The createSequence() docblock contains notes about storing sequence
1717 * @param string $sqn the sequence's public name
1719 * @return string the sequence's name in the backend
1722 * @see DB_common::createSequence(), DB_common::dropSequence(),
1723 * DB_common::nextID(), DB_common::setOption()
1725 function getSequenceName($sqn)
1727 return sprintf($this->getOption('seqname_format'),
1728 preg_replace('/[^a-z0-9_.]/i', '_', $sqn));
1735 * Returns the next free id in a sequence
1737 * @param string $seq_name name of the sequence
1738 * @param boolean $ondemand when true, the seqence is automatically
1739 * created if it does not exist
1741 * @return int the next id number in the sequence.
1742 * A DB_Error object on failure.
1744 * @see DB_common::createSequence(), DB_common::dropSequence(),
1745 * DB_common::getSequenceName()
1747 function nextId($seq_name, $ondemand = true)
1749 return $this->raiseError(DB_ERROR_NOT_CAPABLE);
1753 // {{{ createSequence()
1756 * Creates a new sequence
1758 * The name of a given sequence is determined by passing the string
1759 * provided in the <var>$seq_name</var> argument through PHP's sprintf()
1760 * function using the value from the <var>seqname_format</var> option as
1761 * the sprintf()'s format argument.
1763 * <var>seqname_format</var> is set via setOption().
1765 * @param string $seq_name name of the new sequence
1767 * @return int DB_OK on success. A DB_Error object on failure.
1769 * @see DB_common::dropSequence(), DB_common::getSequenceName(),
1770 * DB_common::nextID()
1772 function createSequence($seq_name)
1774 return $this->raiseError(DB_ERROR_NOT_CAPABLE);
1778 // {{{ dropSequence()
1781 * Deletes a sequence
1783 * @param string $seq_name name of the sequence to be deleted
1785 * @return int DB_OK on success. A DB_Error object on failure.
1787 * @see DB_common::createSequence(), DB_common::getSequenceName(),
1788 * DB_common::nextID()
1790 function dropSequence($seq_name)
1792 return $this->raiseError(DB_ERROR_NOT_CAPABLE);
1799 * Communicates an error and invoke error callbacks, etc
1801 * Basically a wrapper for PEAR::raiseError without the message string.
1803 * @param mixed integer error code, or a PEAR error object (all
1804 * other parameters are ignored if this parameter is
1806 * @param int error mode, see PEAR_Error docs
1807 * @param mixed if error mode is PEAR_ERROR_TRIGGER, this is the
1808 * error level (E_USER_NOTICE etc). If error mode is
1809 * PEAR_ERROR_CALLBACK, this is the callback function,
1810 * either as a function name, or as an array of an
1811 * object and method name. For other error modes this
1812 * parameter is ignored.
1813 * @param string extra debug information. Defaults to the last
1814 * query and native error code.
1815 * @param mixed native error code, integer or string depending the
1818 * @return object the PEAR_Error object
1822 function &raiseError($code = DB_ERROR, $mode = null, $options = null,
1823 $userinfo = null, $nativecode = null)
1825 // The error is yet a DB error object
1826 if (is_object($code)) {
1827 // because we the static PEAR::raiseError, our global
1828 // handler should be used if it is set
1829 if ($mode === null && !empty($this->_default_error_mode)) {
1830 $mode = $this->_default_error_mode;
1831 $options = $this->_default_error_options;
1833 $tmp = PEAR::raiseError($code, null, $mode, $options,
1838 if ($userinfo === null) {
1839 $userinfo = $this->last_query;
1843 $userinfo .= ' [nativecode=' . trim($nativecode) . ']';
1845 $userinfo .= ' [DB Error: ' . DB::errorMessage($code) . ']';
1848 $tmp = PEAR::raiseError(null, $code, $mode, $options, $userinfo,
1854 // {{{ errorNative()
1857 * Gets the DBMS' native error code produced by the last query
1859 * @return mixed the DBMS' error code. A DB_Error object on failure.
1861 function errorNative()
1863 return $this->raiseError(DB_ERROR_NOT_CAPABLE);
1870 * Maps native error codes to DB's portable ones
1872 * Uses the <var>$errorcode_map</var> property defined in each driver.
1874 * @param string|int $nativecode the error code returned by the DBMS
1876 * @return int the portable DB error code. Return DB_ERROR if the
1877 * current driver doesn't have a mapping for the
1878 * $nativecode submitted.
1880 function errorCode($nativecode)
1882 if (isset($this->errorcode_map[$nativecode])) {
1883 return $this->errorcode_map[$nativecode];
1885 // Fall back to DB_ERROR if there was no mapping.
1890 // {{{ errorMessage()
1893 * Maps a DB error code to a textual message
1895 * @param integer $dbcode the DB error code
1897 * @return string the error message corresponding to the error code
1898 * submitted. FALSE if the error code is unknown.
1900 * @see DB::errorMessage()
1902 function errorMessage($dbcode)
1904 return DB::errorMessage($this->errorcode_map[$dbcode]);
1911 * Returns information about a table or a result set
1913 * The format of the resulting array depends on which <var>$mode</var>
1914 * you select. The sample output below is based on this query:
1916 * SELECT tblFoo.fldID, tblFoo.fldPhone, tblBar.fldId
1918 * JOIN tblBar ON tblFoo.fldId = tblBar.fldId
1924 * <kbd>null</kbd> (default)
1931 * [flags] => primary_key not_null
1935 * [name] => fldPhone
1945 * [flags] => primary_key not_null
1951 * <kbd>DB_TABLEINFO_ORDER</kbd>
1953 * <p>In addition to the information found in the default output,
1954 * a notation of the number of columns is provided by the
1955 * <samp>num_fields</samp> element while the <samp>order</samp>
1956 * element provides an array with the column names as the keys and
1957 * their location index number (corresponding to the keys in the
1958 * the default output) as the values.</p>
1960 * <p>If a result set has identical field names, the last one is
1965 * [order] => Array (
1973 * <kbd>DB_TABLEINFO_ORDERTABLE</kbd>
1975 * <p>Similar to <kbd>DB_TABLEINFO_ORDER</kbd> but adds more
1976 * dimensions to the array in which the table names are keys and
1977 * the field names are sub-keys. This is helpful for queries that
1978 * join tables which have identical field names.</p>
1982 * [ordertable] => Array (
1983 * [tblFoo] => Array (
1987 * [tblBar] => Array (
1996 * The <samp>flags</samp> element contains a space separated list
1997 * of extra information about the field. This data is inconsistent
1998 * between DBMS's due to the way each DBMS works.
1999 * + <samp>primary_key</samp>
2000 * + <samp>unique_key</samp>
2001 * + <samp>multiple_key</samp>
2002 * + <samp>not_null</samp>
2004 * Most DBMS's only provide the <samp>table</samp> and <samp>flags</samp>
2005 * elements if <var>$result</var> is a table name. The following DBMS's
2006 * provide full information from queries:
2010 * If the 'portability' option has <samp>DB_PORTABILITY_LOWERCASE</samp>
2011 * turned on, the names of tables and fields will be lowercased.
2013 * @param object|string $result DB_result object from a query or a
2014 * string containing the name of a table.
2015 * While this also accepts a query result
2016 * resource identifier, this behavior is
2018 * @param int $mode either unused or one of the tableInfo modes:
2019 * <kbd>DB_TABLEINFO_ORDERTABLE</kbd>,
2020 * <kbd>DB_TABLEINFO_ORDER</kbd> or
2021 * <kbd>DB_TABLEINFO_FULL</kbd> (which does both).
2022 * These are bitwise, so the first two can be
2023 * combined using <kbd>|</kbd>.
2025 * @return array an associative array with the information requested.
2026 * A DB_Error object on failure.
2028 * @see DB_common::setOption()
2030 function tableInfo($result, $mode = null)
2033 * If the DB_<driver> class has a tableInfo() method, that one
2034 * overrides this one. But, if the driver doesn't have one,
2035 * this method runs and tells users about that fact.
2037 return $this->raiseError(DB_ERROR_NOT_CAPABLE);
2044 * Lists the tables in the current database
2046 * @return array the list of tables. A DB_Error object on failure.
2048 * @deprecated Method deprecated some time before Release 1.2
2050 function getTables()
2052 return $this->getListOf('tables');
2059 * Lists internal database information
2061 * @param string $type type of information being sought.
2062 * Common items being sought are:
2063 * tables, databases, users, views, functions
2064 * Each DBMS's has its own capabilities.
2066 * @return array an array listing the items sought.
2067 * A DB DB_Error object on failure.
2069 function getListOf($type)
2071 $sql = $this->getSpecialQuery($type);
2072 if ($sql === null) {
2073 $this->last_query = '';
2074 return $this->raiseError(DB_ERROR_UNSUPPORTED);
2075 } elseif (is_int($sql) || DB::isError($sql)) {
2077 return $this->raiseError($sql);
2078 } elseif (is_array($sql)) {
2079 // Already the result
2082 // Launch this query
2083 return $this->getCol($sql);
2087 // {{{ getSpecialQuery()
2090 * Obtains the query string needed for listing a given type of objects
2092 * @param string $type the kind of objects you want to retrieve
2094 * @return string the SQL query string or null if the driver doesn't
2095 * support the object type requested
2098 * @see DB_common::getListOf()
2100 function getSpecialQuery($type)
2102 return $this->raiseError(DB_ERROR_UNSUPPORTED);
2106 // {{{ _rtrimArrayValues()
2109 * Right-trims all strings in an array
2111 * @param array $array the array to be trimmed (passed by reference)
2117 function _rtrimArrayValues(&$array)
2119 foreach ($array as $key => $value) {
2120 if (is_string($value)) {
2121 $array[$key] = rtrim($value);
2127 // {{{ _convertNullArrayValuesToEmpty()
2130 * Converts all null values in an array to empty strings
2132 * @param array $array the array to be de-nullified (passed by reference)
2138 function _convertNullArrayValuesToEmpty(&$array)
2140 foreach ($array as $key => $value) {
2141 if (is_null($value)) {