3 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
6 * The PEAR DB driver for PHP's mysqli extension
7 * for interacting with MySQL databases
11 * LICENSE: This source file is subject to version 3.0 of the PHP license
12 * that is available through the world-wide-web at the following URI:
13 * http://www.php.net/license/3_0.txt. If you did not receive a copy of
14 * the PHP License and are unable to obtain it through the web, please
15 * send a note to license@php.net so we can mail you a copy immediately.
19 * @author Daniel Convissor <danielc@php.net>
20 * @copyright 1997-2007 The PHP Group
21 * @license http://www.php.net/license/3_0.txt PHP License 3.0
22 * @version CVS: $Id: mysqli.php,v 1.82 2007/09/21 13:40:41 aharvey Exp $
23 * @link http://pear.php.net/package/DB
27 * Obtain the DB_common class so it can be extended from
29 require_once 'DB/common.php';
32 * The methods PEAR DB uses to interact with PHP's mysqli extension
33 * for interacting with MySQL databases
35 * This is for MySQL versions 4.1 and above. Requires PHP 5.
37 * Note that persistent connections no longer exist.
39 * These methods overload the ones declared in DB_common.
43 * @author Daniel Convissor <danielc@php.net>
44 * @copyright 1997-2007 The PHP Group
45 * @license http://www.php.net/license/3_0.txt PHP License 3.0
46 * @version Release: 1.7.14RC1
47 * @link http://pear.php.net/package/DB
48 * @since Class functional since Release 1.6.3
50 class DB_mysqli extends DB_common
55 * The DB driver type (mysql, oci8, odbc, etc.)
58 var $phptype = 'mysqli';
61 * The database syntax variant to be used (db2, access, etc.), if any
64 var $dbsyntax = 'mysqli';
67 * The capabilities of this DB implementation
69 * The 'new_link' element contains the PHP version that first provided
70 * new_link support for this DBMS. Contains false if it's unsupported.
72 * Meaning of the 'limit' element:
73 * + 'emulate' = emulate with fetch row by number
74 * + 'alter' = alter the query
79 var $features = array(
86 'transactions' => true,
90 * A mapping of native error codes to DB error codes
93 var $errorcode_map = array(
94 1004 => DB_ERROR_CANNOT_CREATE,
95 1005 => DB_ERROR_CANNOT_CREATE,
96 1006 => DB_ERROR_CANNOT_CREATE,
97 1007 => DB_ERROR_ALREADY_EXISTS,
98 1008 => DB_ERROR_CANNOT_DROP,
99 1022 => DB_ERROR_ALREADY_EXISTS,
100 1044 => DB_ERROR_ACCESS_VIOLATION,
101 1046 => DB_ERROR_NODBSELECTED,
102 1048 => DB_ERROR_CONSTRAINT,
103 1049 => DB_ERROR_NOSUCHDB,
104 1050 => DB_ERROR_ALREADY_EXISTS,
105 1051 => DB_ERROR_NOSUCHTABLE,
106 1054 => DB_ERROR_NOSUCHFIELD,
107 1061 => DB_ERROR_ALREADY_EXISTS,
108 1062 => DB_ERROR_ALREADY_EXISTS,
109 1064 => DB_ERROR_SYNTAX,
110 1091 => DB_ERROR_NOT_FOUND,
111 1100 => DB_ERROR_NOT_LOCKED,
112 1136 => DB_ERROR_VALUE_COUNT_ON_ROW,
113 1142 => DB_ERROR_ACCESS_VIOLATION,
114 1146 => DB_ERROR_NOSUCHTABLE,
115 1216 => DB_ERROR_CONSTRAINT,
116 1217 => DB_ERROR_CONSTRAINT,
117 1356 => DB_ERROR_DIVZERO,
118 1451 => DB_ERROR_CONSTRAINT,
119 1452 => DB_ERROR_CONSTRAINT,
123 * The raw database connection created by PHP
129 * The DSN information for connecting to a database
136 * Should data manipulation queries be committed automatically?
140 var $autocommit = true;
143 * The quantity of transactions begun
145 * {@internal While this is private, it can't actually be designated
146 * private in PHP 5 because it is directly accessed in the test suite.}}
151 var $transaction_opcount = 0;
154 * The database specified in the DSN
156 * It's a fix to allow calls to different databases in the same script.
164 * Array for converting MYSQLI_*_FLAG constants to text values
167 * @since Property available since Release 1.6.5
169 var $mysqli_flags = array(
170 MYSQLI_NOT_NULL_FLAG => 'not_null',
171 MYSQLI_PRI_KEY_FLAG => 'primary_key',
172 MYSQLI_UNIQUE_KEY_FLAG => 'unique_key',
173 MYSQLI_MULTIPLE_KEY_FLAG => 'multiple_key',
174 MYSQLI_BLOB_FLAG => 'blob',
175 MYSQLI_UNSIGNED_FLAG => 'unsigned',
176 MYSQLI_ZEROFILL_FLAG => 'zerofill',
177 MYSQLI_AUTO_INCREMENT_FLAG => 'auto_increment',
178 MYSQLI_TIMESTAMP_FLAG => 'timestamp',
179 MYSQLI_SET_FLAG => 'set',
180 // MYSQLI_NUM_FLAG => 'numeric', // unnecessary
181 // MYSQLI_PART_KEY_FLAG => 'multiple_key', // duplicatvie
182 MYSQLI_GROUP_FLAG => 'group_by'
186 * Array for converting MYSQLI_TYPE_* constants to text values
189 * @since Property available since Release 1.6.5
191 var $mysqli_types = array(
192 MYSQLI_TYPE_DECIMAL => 'decimal',
193 MYSQLI_TYPE_TINY => 'tinyint',
194 MYSQLI_TYPE_SHORT => 'int',
195 MYSQLI_TYPE_LONG => 'int',
196 MYSQLI_TYPE_FLOAT => 'float',
197 MYSQLI_TYPE_DOUBLE => 'double',
198 // MYSQLI_TYPE_NULL => 'DEFAULT NULL', // let flags handle it
199 MYSQLI_TYPE_TIMESTAMP => 'timestamp',
200 MYSQLI_TYPE_LONGLONG => 'bigint',
201 MYSQLI_TYPE_INT24 => 'mediumint',
202 MYSQLI_TYPE_DATE => 'date',
203 MYSQLI_TYPE_TIME => 'time',
204 MYSQLI_TYPE_DATETIME => 'datetime',
205 MYSQLI_TYPE_YEAR => 'year',
206 MYSQLI_TYPE_NEWDATE => 'date',
207 MYSQLI_TYPE_ENUM => 'enum',
208 MYSQLI_TYPE_SET => 'set',
209 MYSQLI_TYPE_TINY_BLOB => 'tinyblob',
210 MYSQLI_TYPE_MEDIUM_BLOB => 'mediumblob',
211 MYSQLI_TYPE_LONG_BLOB => 'longblob',
212 MYSQLI_TYPE_BLOB => 'blob',
213 MYSQLI_TYPE_VAR_STRING => 'varchar',
214 MYSQLI_TYPE_STRING => 'char',
215 MYSQLI_TYPE_GEOMETRY => 'geometry',
216 /* These constants are conditionally compiled in ext/mysqli, so we'll
217 * define them by number rather than constant. */
227 * This constructor calls <kbd>$this->DB_common()</kbd>
240 * Connect to the database server, log in and open the database
242 * Don't call this method directly. Use DB::connect() instead.
244 * PEAR DB's mysqli driver supports the following extra DSN options:
245 * + When the 'ssl' $option passed to DB::connect() is true:
246 * + key The path to the key file.
247 * + cert The path to the certificate file.
248 * + ca The path to the certificate authority file.
249 * + capath The path to a directory that contains trusted SSL
250 * CA certificates in pem format.
251 * + cipher The list of allowable ciphers for SSL encryption.
253 * Example of how to connect using SSL:
255 * require_once 'DB.php';
258 * 'phptype' => 'mysqli',
259 * 'username' => 'someuser',
260 * 'password' => 'apasswd',
261 * 'hostspec' => 'localhost',
262 * 'database' => 'thedb',
263 * 'key' => 'client-key.pem',
264 * 'cert' => 'client-cert.pem',
265 * 'ca' => 'cacert.pem',
266 * 'capath' => '/path/to/ca/dir',
274 * $db = DB::connect($dsn, $options);
275 * if (PEAR::isError($db)) {
276 * die($db->getMessage());
280 * @param array $dsn the data source name
281 * @param bool $persistent should the connection be persistent?
283 * @return int DB_OK on success. A DB_Error object on failure.
285 function connect($dsn, $persistent = false)
287 if (!PEAR::loadExtension('mysqli')) {
288 return $this->raiseError(DB_ERROR_EXTENSION_NOT_FOUND);
292 if ($dsn['dbsyntax']) {
293 $this->dbsyntax = $dsn['dbsyntax'];
296 $ini = ini_get('track_errors');
297 @ini_set('track_errors', 1);
300 if (((int) $this->getOption('ssl')) === 1) {
301 $init = mysqli_init();
304 empty($dsn['key']) ? null : $dsn['key'],
305 empty($dsn['cert']) ? null : $dsn['cert'],
306 empty($dsn['ca']) ? null : $dsn['ca'],
307 empty($dsn['capath']) ? null : $dsn['capath'],
308 empty($dsn['cipher']) ? null : $dsn['cipher']
310 if ($this->connection = @mysqli_real_connect(
319 $this->connection = $init;
322 $this->connection = @mysqli_connect(
332 @ini_set('track_errors', $ini);
334 if (!$this->connection) {
335 if (($err = @mysqli_connect_error()) != '') {
336 return $this->raiseError(DB_ERROR_CONNECT_FAILED,
340 return $this->raiseError(DB_ERROR_CONNECT_FAILED,
346 if ($dsn['database']) {
347 $this->_db = $dsn['database'];
357 * Disconnects from the database server
359 * @return bool TRUE on success, FALSE on failure
361 function disconnect()
363 $ret = @mysqli_close($this->connection);
364 $this->connection = null;
372 * Sends a query to the database server
374 * @param string the SQL query string
376 * @return mixed + a PHP result resrouce for successful SELECT queries
377 * + the DB_OK constant for other successful queries
378 * + a DB_Error object on failure
380 function simpleQuery($query)
382 $ismanip = $this->_checkManip($query);
383 $this->last_query = $query;
384 $query = $this->modifyQuery($query);
386 if (!@mysqli_select_db($this->connection, $this->_db)) {
387 return $this->mysqliRaiseError(DB_ERROR_NODBSELECTED);
390 if (!$this->autocommit && $ismanip) {
391 if ($this->transaction_opcount == 0) {
392 $result = @mysqli_query($this->connection, 'SET AUTOCOMMIT=0');
393 $result = @mysqli_query($this->connection, 'BEGIN');
395 return $this->mysqliRaiseError();
398 $this->transaction_opcount++;
400 $result = @mysqli_query($this->connection, $query);
402 return $this->mysqliRaiseError();
404 if (is_object($result)) {
414 * Move the internal mysql result pointer to the next available result.
416 * This method has not been implemented yet.
418 * @param resource $result a valid sql result resource
422 function nextResult($result)
431 * Places a row from the result set into the given array
433 * Formating of the array and the data therein are configurable.
434 * See DB_result::fetchInto() for more information.
436 * This method is not meant to be called directly. Use
437 * DB_result::fetchInto() instead. It can't be declared "protected"
438 * because DB_result is a separate object.
440 * @param resource $result the query result resource
441 * @param array $arr the referenced array to put the data in
442 * @param int $fetchmode how the resulting array should be indexed
443 * @param int $rownum the row number to fetch (0 = first row)
445 * @return mixed DB_OK on success, NULL when the end of a result set is
446 * reached or on failure
448 * @see DB_result::fetchInto()
450 function fetchInto($result, &$arr, $fetchmode, $rownum = null)
452 if ($rownum !== null) {
453 if (!@mysqli_data_seek($result, $rownum)) {
457 if ($fetchmode & DB_FETCHMODE_ASSOC) {
458 $arr = @mysqli_fetch_array($result, MYSQLI_ASSOC);
459 if ($this->options['portability'] & DB_PORTABILITY_LOWERCASE && $arr) {
460 $arr = array_change_key_case($arr, CASE_LOWER);
463 $arr = @mysqli_fetch_row($result);
468 if ($this->options['portability'] & DB_PORTABILITY_RTRIM) {
470 * Even though this DBMS already trims output, we do this because
471 * a field might have intentional whitespace at the end that
472 * gets removed by DB_PORTABILITY_RTRIM under another driver.
474 $this->_rtrimArrayValues($arr);
476 if ($this->options['portability'] & DB_PORTABILITY_NULL_TO_EMPTY) {
477 $this->_convertNullArrayValuesToEmpty($arr);
486 * Deletes the result set and frees the memory occupied by the result set
488 * This method is not meant to be called directly. Use
489 * DB_result::free() instead. It can't be declared "protected"
490 * because DB_result is a separate object.
492 * @param resource $result PHP's query result resource
494 * @return bool TRUE on success, FALSE if $result is invalid
496 * @see DB_result::free()
498 function freeResult($result)
500 return is_resource($result) ? mysqli_free_result($result) : false;
507 * Gets the number of columns in a result set
509 * This method is not meant to be called directly. Use
510 * DB_result::numCols() instead. It can't be declared "protected"
511 * because DB_result is a separate object.
513 * @param resource $result PHP's query result resource
515 * @return int the number of columns. A DB_Error object on failure.
517 * @see DB_result::numCols()
519 function numCols($result)
521 $cols = @mysqli_num_fields($result);
523 return $this->mysqliRaiseError();
532 * Gets the number of rows in a result set
534 * This method is not meant to be called directly. Use
535 * DB_result::numRows() instead. It can't be declared "protected"
536 * because DB_result is a separate object.
538 * @param resource $result PHP's query result resource
540 * @return int the number of rows. A DB_Error object on failure.
542 * @see DB_result::numRows()
544 function numRows($result)
546 $rows = @mysqli_num_rows($result);
547 if ($rows === null) {
548 return $this->mysqliRaiseError();
557 * Enables or disables automatic commits
559 * @param bool $onoff true turns it on, false turns it off
561 * @return int DB_OK on success. A DB_Error object if the driver
562 * doesn't support auto-committing transactions.
564 function autoCommit($onoff = false)
566 // XXX if $this->transaction_opcount > 0, we should probably
567 // issue a warning here.
568 $this->autocommit = $onoff ? true : false;
576 * Commits the current transaction
578 * @return int DB_OK on success. A DB_Error object on failure.
582 if ($this->transaction_opcount > 0) {
584 if (!@mysqli_select_db($this->connection, $this->_db)) {
585 return $this->mysqliRaiseError(DB_ERROR_NODBSELECTED);
588 $result = @mysqli_query($this->connection, 'COMMIT');
589 $result = @mysqli_query($this->connection, 'SET AUTOCOMMIT=1');
590 $this->transaction_opcount = 0;
592 return $this->mysqliRaiseError();
602 * Reverts the current transaction
604 * @return int DB_OK on success. A DB_Error object on failure.
608 if ($this->transaction_opcount > 0) {
610 if (!@mysqli_select_db($this->connection, $this->_db)) {
611 return $this->mysqliRaiseError(DB_ERROR_NODBSELECTED);
614 $result = @mysqli_query($this->connection, 'ROLLBACK');
615 $result = @mysqli_query($this->connection, 'SET AUTOCOMMIT=1');
616 $this->transaction_opcount = 0;
618 return $this->mysqliRaiseError();
625 // {{{ affectedRows()
628 * Determines the number of rows affected by a data maniuplation query
630 * 0 is returned for queries that don't manipulate data.
632 * @return int the number of rows. A DB_Error object on failure.
634 function affectedRows()
636 if ($this->_last_query_manip) {
637 return @mysqli_affected_rows($this->connection);
647 * Returns the next free id in a sequence
649 * @param string $seq_name name of the sequence
650 * @param boolean $ondemand when true, the seqence is automatically
651 * created if it does not exist
653 * @return int the next id number in the sequence.
654 * A DB_Error object on failure.
656 * @see DB_common::nextID(), DB_common::getSequenceName(),
657 * DB_mysqli::createSequence(), DB_mysqli::dropSequence()
659 function nextId($seq_name, $ondemand = true)
661 $seqname = $this->getSequenceName($seq_name);
664 $this->pushErrorHandling(PEAR_ERROR_RETURN);
665 $result = $this->query('UPDATE ' . $seqname
666 . ' SET id = LAST_INSERT_ID(id + 1)');
667 $this->popErrorHandling();
668 if ($result === DB_OK) {
670 $id = @mysqli_insert_id($this->connection);
676 // Sequence table must be empty for some reason,
677 // so fill it and return 1
678 // Obtain a user-level lock
679 $result = $this->getOne('SELECT GET_LOCK('
680 . "'${seqname}_lock', 10)");
681 if (DB::isError($result)) {
682 return $this->raiseError($result);
685 return $this->mysqliRaiseError(DB_ERROR_NOT_LOCKED);
688 // add the default value
689 $result = $this->query('REPLACE INTO ' . $seqname
690 . ' (id) VALUES (0)');
691 if (DB::isError($result)) {
692 return $this->raiseError($result);
696 $result = $this->getOne('SELECT RELEASE_LOCK('
697 . "'${seqname}_lock')");
698 if (DB::isError($result)) {
699 return $this->raiseError($result);
701 // We know what the result will be, so no need to try again
704 } elseif ($ondemand && DB::isError($result) &&
705 $result->getCode() == DB_ERROR_NOSUCHTABLE)
707 // ONDEMAND TABLE CREATION
708 $result = $this->createSequence($seq_name);
710 // Since createSequence initializes the ID to be 1,
711 // we do not need to retrieve the ID again (or we will get 2)
712 if (DB::isError($result)) {
713 return $this->raiseError($result);
715 // First ID of a newly created sequence is 1
719 } elseif (DB::isError($result) &&
720 $result->getCode() == DB_ERROR_ALREADY_EXISTS)
723 // see _BCsequence() comment
724 $result = $this->_BCsequence($seqname);
725 if (DB::isError($result)) {
726 return $this->raiseError($result);
732 return $this->raiseError($result);
736 * Creates a new sequence
738 * @param string $seq_name name of the new sequence
740 * @return int DB_OK on success. A DB_Error object on failure.
742 * @see DB_common::createSequence(), DB_common::getSequenceName(),
743 * DB_mysqli::nextID(), DB_mysqli::dropSequence()
745 function createSequence($seq_name)
747 $seqname = $this->getSequenceName($seq_name);
748 $res = $this->query('CREATE TABLE ' . $seqname
749 . ' (id INTEGER UNSIGNED AUTO_INCREMENT NOT NULL,'
750 . ' PRIMARY KEY(id))');
751 if (DB::isError($res)) {
754 // insert yields value 1, nextId call will generate ID 2
755 return $this->query("INSERT INTO ${seqname} (id) VALUES (0)");
759 // {{{ dropSequence()
764 * @param string $seq_name name of the sequence to be deleted
766 * @return int DB_OK on success. A DB_Error object on failure.
768 * @see DB_common::dropSequence(), DB_common::getSequenceName(),
769 * DB_mysql::nextID(), DB_mysql::createSequence()
771 function dropSequence($seq_name)
773 return $this->query('DROP TABLE ' . $this->getSequenceName($seq_name));
780 * Backwards compatibility with old sequence emulation implementation
781 * (clean up the dupes)
783 * @param string $seqname the sequence name to clean up
785 * @return bool true on success. A DB_Error object on failure.
789 function _BCsequence($seqname)
791 // Obtain a user-level lock... this will release any previous
792 // application locks, but unlike LOCK TABLES, it does not abort
793 // the current transaction and is much less frequently used.
794 $result = $this->getOne("SELECT GET_LOCK('${seqname}_lock',10)");
795 if (DB::isError($result)) {
799 // Failed to get the lock, can't do the conversion, bail
800 // with a DB_ERROR_NOT_LOCKED error
801 return $this->mysqliRaiseError(DB_ERROR_NOT_LOCKED);
804 $highest_id = $this->getOne("SELECT MAX(id) FROM ${seqname}");
805 if (DB::isError($highest_id)) {
809 // This should kill all rows except the highest
810 // We should probably do something if $highest_id isn't
811 // numeric, but I'm at a loss as how to handle that...
812 $result = $this->query('DELETE FROM ' . $seqname
813 . " WHERE id <> $highest_id");
814 if (DB::isError($result)) {
818 // If another thread has been waiting for this lock,
819 // it will go thru the above procedure, but will have no
821 $result = $this->getOne("SELECT RELEASE_LOCK('${seqname}_lock')");
822 if (DB::isError($result)) {
829 // {{{ quoteIdentifier()
832 * Quotes a string so it can be safely used as a table or column name
833 * (WARNING: using names that require this is a REALLY BAD IDEA)
835 * WARNING: Older versions of MySQL can't handle the backtick
836 * character (<kbd>`</kbd>) in table or column names.
838 * @param string $str identifier name to be quoted
840 * @return string quoted identifier string
842 * @see DB_common::quoteIdentifier()
843 * @since Method available since Release 1.6.0
845 function quoteIdentifier($str)
847 return '`' . str_replace('`', '``', $str) . '`';
851 // {{{ escapeSimple()
854 * Escapes a string according to the current DBMS's standards
856 * @param string $str the string to be escaped
858 * @return string the escaped string
860 * @see DB_common::quoteSmart()
861 * @since Method available since Release 1.6.0
863 function escapeSimple($str)
865 return @mysqli_real_escape_string($this->connection, $str);
869 // {{{ modifyLimitQuery()
872 * Adds LIMIT clauses to a query string according to current DBMS standards
874 * @param string $query the query to modify
875 * @param int $from the row to start to fetching (0 = the first row)
876 * @param int $count the numbers of rows to fetch
877 * @param mixed $params array, string or numeric data to be used in
878 * execution of the statement. Quantity of items
879 * passed must match quantity of placeholders in
880 * query: meaning 1 placeholder for non-array
881 * parameters or 1 placeholder per array element.
883 * @return string the query string with LIMIT clauses added
887 function modifyLimitQuery($query, $from, $count, $params = array())
889 if (DB::isManip($query) || $this->_next_query_manip) {
890 return $query . " LIMIT $count";
892 return $query . " LIMIT $from, $count";
897 // {{{ mysqliRaiseError()
900 * Produces a DB_Error object regarding the current problem
902 * @param int $errno if the error is being manually raised pass a
903 * DB_ERROR* constant here. If this isn't passed
904 * the error information gathered from the DBMS.
906 * @return object the DB_Error object
908 * @see DB_common::raiseError(),
909 * DB_mysqli::errorNative(), DB_common::errorCode()
911 function mysqliRaiseError($errno = null)
913 if ($errno === null) {
914 if ($this->options['portability'] & DB_PORTABILITY_ERRORS) {
915 $this->errorcode_map[1022] = DB_ERROR_CONSTRAINT;
916 $this->errorcode_map[1048] = DB_ERROR_CONSTRAINT_NOT_NULL;
917 $this->errorcode_map[1062] = DB_ERROR_CONSTRAINT;
919 // Doing this in case mode changes during runtime.
920 $this->errorcode_map[1022] = DB_ERROR_ALREADY_EXISTS;
921 $this->errorcode_map[1048] = DB_ERROR_CONSTRAINT;
922 $this->errorcode_map[1062] = DB_ERROR_ALREADY_EXISTS;
924 $errno = $this->errorCode(mysqli_errno($this->connection));
926 return $this->raiseError($errno, null, null, null,
927 @mysqli_errno($this->connection) . ' ** ' .
928 @mysqli_error($this->connection));
935 * Gets the DBMS' native error code produced by the last query
937 * @return int the DBMS' error code
939 function errorNative()
941 return @mysqli_errno($this->connection);
948 * Returns information about a table or a result set
950 * @param object|string $result DB_result object from a query or a
951 * string containing the name of a table.
952 * While this also accepts a query result
953 * resource identifier, this behavior is
955 * @param int $mode a valid tableInfo mode
957 * @return array an associative array with the information requested.
958 * A DB_Error object on failure.
960 * @see DB_common::setOption()
962 function tableInfo($result, $mode = null)
964 if (is_string($result)) {
965 // Fix for bug #11580.
967 if (!@mysqli_select_db($this->connection, $this->_db)) {
968 return $this->mysqliRaiseError(DB_ERROR_NODBSELECTED);
973 * Probably received a table name.
974 * Create a result resource identifier.
976 $id = @mysqli_query($this->connection,
977 "SELECT * FROM $result LIMIT 0");
979 } elseif (isset($result->result)) {
981 * Probably received a result object.
982 * Extract the result resource identifier.
984 $id = $result->result;
988 * Probably received a result resource identifier.
990 * Deprecated. Here for compatibility only.
996 if (!is_a($id, 'mysqli_result')) {
997 return $this->mysqliRaiseError(DB_ERROR_NEED_MORE_DATA);
1000 if ($this->options['portability'] & DB_PORTABILITY_LOWERCASE) {
1001 $case_func = 'strtolower';
1003 $case_func = 'strval';
1006 $count = @mysqli_num_fields($id);
1010 $res['num_fields'] = $count;
1013 for ($i = 0; $i < $count; $i++) {
1014 $tmp = @mysqli_fetch_field($id);
1017 foreach ($this->mysqli_flags as $const => $means) {
1018 if ($tmp->flags & $const) {
1019 $flags .= $means . ' ';
1023 $flags .= 'default_' . rawurlencode($tmp->def);
1025 $flags = trim($flags);
1028 'table' => $case_func($tmp->table),
1029 'name' => $case_func($tmp->name),
1030 'type' => isset($this->mysqli_types[$tmp->type])
1031 ? $this->mysqli_types[$tmp->type]
1033 // http://bugs.php.net/?id=36579
1034 'len' => $tmp->length,
1038 if ($mode & DB_TABLEINFO_ORDER) {
1039 $res['order'][$res[$i]['name']] = $i;
1041 if ($mode & DB_TABLEINFO_ORDERTABLE) {
1042 $res['ordertable'][$res[$i]['table']][$res[$i]['name']] = $i;
1046 // free the result only if we were called on a table
1048 @mysqli_free_result($id);
1054 // {{{ getSpecialQuery()
1057 * Obtains the query string needed for listing a given type of objects
1059 * @param string $type the kind of objects you want to retrieve
1061 * @return string the SQL query string or null if the driver doesn't
1062 * support the object type requested
1065 * @see DB_common::getListOf()
1067 function getSpecialQuery($type)
1071 return 'SHOW TABLES';
1073 return 'SELECT DISTINCT User FROM mysql.user';
1075 return 'SHOW DATABASES';