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
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';
30 require_once 'common.php';
33 * The methods PEAR DB uses to interact with PHP's mysqli extension
34 * for interacting with MySQL databases
36 * This is for MySQL versions 4.1 and above. Requires PHP 5.
38 * Note that persistent connections no longer exist.
40 * These methods overload the ones declared in DB_common.
44 * @author Daniel Convissor <danielc@php.net>
45 * @copyright 1997-2007 The PHP Group
46 * @license http://www.php.net/license/3_0.txt PHP License 3.0
47 * @version Release: 1.9.2
48 * @link http://pear.php.net/package/DB
49 * @since Class functional since Release 1.6.3
51 class DB_mysqli extends DB_common
56 * The DB driver type (mysql, oci8, odbc, etc.)
59 public $phptype = 'mysqli';
62 * The database syntax variant to be used (db2, access, etc.), if any
65 public $dbsyntax = 'mysqli';
68 * The capabilities of this DB implementation
70 * The 'new_link' element contains the PHP version that first provided
71 * new_link support for this DBMS. Contains false if it's unsupported.
73 * Meaning of the 'limit' element:
74 * + 'emulate' = emulate with fetch row by number
75 * + 'alter' = alter the query
80 public $features = array(
87 'transactions' => true,
91 * A mapping of native error codes to DB error codes
94 public $errorcode_map = array(
95 1004 => DB_ERROR_CANNOT_CREATE,
96 1005 => DB_ERROR_CANNOT_CREATE,
97 1006 => DB_ERROR_CANNOT_CREATE,
98 1007 => DB_ERROR_ALREADY_EXISTS,
99 1008 => DB_ERROR_CANNOT_DROP,
100 1022 => DB_ERROR_ALREADY_EXISTS,
101 1044 => DB_ERROR_ACCESS_VIOLATION,
102 1046 => DB_ERROR_NODBSELECTED,
103 1048 => DB_ERROR_CONSTRAINT,
104 1049 => DB_ERROR_NOSUCHDB,
105 1050 => DB_ERROR_ALREADY_EXISTS,
106 1051 => DB_ERROR_NOSUCHTABLE,
107 1054 => DB_ERROR_NOSUCHFIELD,
108 1061 => DB_ERROR_ALREADY_EXISTS,
109 1062 => DB_ERROR_ALREADY_EXISTS,
110 1064 => DB_ERROR_SYNTAX,
111 1091 => DB_ERROR_NOT_FOUND,
112 1100 => DB_ERROR_NOT_LOCKED,
113 1136 => DB_ERROR_VALUE_COUNT_ON_ROW,
114 1142 => DB_ERROR_ACCESS_VIOLATION,
115 1146 => DB_ERROR_NOSUCHTABLE,
116 1216 => DB_ERROR_CONSTRAINT,
117 1217 => DB_ERROR_CONSTRAINT,
118 1356 => DB_ERROR_DIVZERO,
119 1451 => DB_ERROR_CONSTRAINT,
120 1452 => DB_ERROR_CONSTRAINT,
124 * The raw database connection created by PHP
130 * The DSN information for connecting to a database
133 public $dsn = array();
137 * Should data manipulation queries be committed automatically?
141 public $autocommit = true;
144 * The quantity of transactions begun
146 * {@internal While this is private, it can't actually be designated
147 * private in PHP 5 because it is directly accessed in the test suite.}}
152 public $transaction_opcount = 0;
155 * The database specified in the DSN
157 * It's a fix to allow calls to different databases in the same script.
165 * Array for converting MYSQLI_*_FLAG constants to text values
168 * @since Property available since Release 1.6.5
170 public $mysqli_flags = array(
171 MYSQLI_NOT_NULL_FLAG => 'not_null',
172 MYSQLI_PRI_KEY_FLAG => 'primary_key',
173 MYSQLI_UNIQUE_KEY_FLAG => 'unique_key',
174 MYSQLI_MULTIPLE_KEY_FLAG => 'multiple_key',
175 MYSQLI_BLOB_FLAG => 'blob',
176 MYSQLI_UNSIGNED_FLAG => 'unsigned',
177 MYSQLI_ZEROFILL_FLAG => 'zerofill',
178 MYSQLI_AUTO_INCREMENT_FLAG => 'auto_increment',
179 MYSQLI_TIMESTAMP_FLAG => 'timestamp',
180 MYSQLI_SET_FLAG => 'set',
181 // MYSQLI_NUM_FLAG => 'numeric', // unnecessary
182 // MYSQLI_PART_KEY_FLAG => 'multiple_key', // duplicatvie
183 MYSQLI_GROUP_FLAG => 'group_by'
187 * Array for converting MYSQLI_TYPE_* constants to text values
190 * @since Property available since Release 1.6.5
192 public $mysqli_types = array(
193 MYSQLI_TYPE_DECIMAL => 'decimal',
194 MYSQLI_TYPE_TINY => 'tinyint',
195 MYSQLI_TYPE_SHORT => 'int',
196 MYSQLI_TYPE_LONG => 'int',
197 MYSQLI_TYPE_FLOAT => 'float',
198 MYSQLI_TYPE_DOUBLE => 'double',
199 // MYSQLI_TYPE_NULL => 'DEFAULT NULL', // let flags handle it
200 MYSQLI_TYPE_TIMESTAMP => 'timestamp',
201 MYSQLI_TYPE_LONGLONG => 'bigint',
202 MYSQLI_TYPE_INT24 => 'mediumint',
203 MYSQLI_TYPE_DATE => 'date',
204 MYSQLI_TYPE_TIME => 'time',
205 MYSQLI_TYPE_DATETIME => 'datetime',
206 MYSQLI_TYPE_YEAR => 'year',
207 MYSQLI_TYPE_NEWDATE => 'date',
208 MYSQLI_TYPE_ENUM => 'enum',
209 MYSQLI_TYPE_SET => 'set',
210 MYSQLI_TYPE_TINY_BLOB => 'tinyblob',
211 MYSQLI_TYPE_MEDIUM_BLOB => 'mediumblob',
212 MYSQLI_TYPE_LONG_BLOB => 'longblob',
213 MYSQLI_TYPE_BLOB => 'blob',
214 MYSQLI_TYPE_VAR_STRING => 'varchar',
215 MYSQLI_TYPE_STRING => 'char',
216 MYSQLI_TYPE_GEOMETRY => 'geometry',
217 /* These constants are conditionally compiled in ext/mysqli, so we'll
218 * define them by number rather than constant. */
228 * This constructor calls <kbd>parent::__construct()</kbd>
232 public function __construct()
234 parent::__construct();
241 * Connect to the database server, log in and open the database
243 * Don't call this method directly. Use DB::connect() instead.
245 * PEAR DB's mysqli driver supports the following extra DSN options:
246 * + When the 'ssl' $option passed to DB::connect() is true:
247 * + key The path to the key file.
248 * + cert The path to the certificate file.
249 * + ca The path to the certificate authority file.
250 * + capath The path to a directory that contains trusted SSL
251 * CA certificates in pem format.
252 * + cipher The list of allowable ciphers for SSL encryption.
254 * Example of how to connect using SSL:
256 * require_once 'DB.php';
259 * 'phptype' => 'mysqli',
260 * 'username' => 'someuser',
261 * 'password' => 'apasswd',
262 * 'hostspec' => 'localhost',
263 * 'database' => 'thedb',
264 * 'key' => 'client-key.pem',
265 * 'cert' => 'client-cert.pem',
266 * 'ca' => 'cacert.pem',
267 * 'capath' => '/path/to/ca/dir',
275 * $db = DB::connect($dsn, $options);
276 * if ((new PEAR)->isError($db)) {
277 * die($db->getMessage());
281 * @param array $dsn the data source name
282 * @param bool $persistent should the connection be persistent?
286 public function connect($dsn, $persistent = false)
288 if (!PEAR::loadExtension('mysqli')) {
289 return $this->raiseError(DB_ERROR_EXTENSION_NOT_FOUND);
293 if ($dsn['dbsyntax']) {
294 $this->dbsyntax = $dsn['dbsyntax'];
297 $ini = ini_get('track_errors');
298 @ini_set('track_errors', 1);
301 if (((int)$this->getOption('ssl')) === 1) {
302 $init = mysqli_init();
305 empty($dsn['key']) ? null : $dsn['key'],
306 empty($dsn['cert']) ? null : $dsn['cert'],
307 empty($dsn['ca']) ? null : $dsn['ca'],
308 empty($dsn['capath']) ? null : $dsn['capath'],
309 empty($dsn['cipher']) ? null : $dsn['cipher']
311 if ($this->connection = @mysqli_real_connect(
320 $this->connection = $init;
323 $this->connection = @mysqli_connect(
333 @ini_set('track_errors', $ini);
335 if (!$this->connection) {
336 if (($err = @mysqli_connect_error()) != '') {
337 return $this->raiseError(
338 DB_ERROR_CONNECT_FAILED,
345 return $this->raiseError(
346 DB_ERROR_CONNECT_FAILED,
355 if ($dsn['database']) {
356 $this->_db = $dsn['database'];
366 * Disconnects from the database server
368 * @return bool TRUE on success, FALSE on failure
370 public function disconnect()
372 $ret = @mysqli_close($this->connection);
373 $this->connection = null;
381 * Sends a query to the database server
383 * @param string the SQL query string
385 * @return mixed + a PHP result resrouce for successful SELECT queries
386 * + the DB_OK constant for other successful queries
387 * + a DB_Error object on failure
389 public function simpleQuery($query)
391 $ismanip = $this->_checkManip($query);
392 $this->last_query = $query;
393 $query = $this->modifyQuery($query);
395 if (!@mysqli_select_db($this->connection, $this->_db)) {
396 return $this->mysqliRaiseError(DB_ERROR_NODBSELECTED);
399 if (!$this->autocommit && $ismanip) {
400 if ($this->transaction_opcount == 0) {
401 $result = @mysqli_query($this->connection, 'SET AUTOCOMMIT=0');
402 $result = @mysqli_query($this->connection, 'BEGIN');
404 return $this->mysqliRaiseError();
407 $this->transaction_opcount++;
409 $result = @mysqli_query($this->connection, $query);
411 return $this->mysqliRaiseError();
413 if (is_object($result)) {
423 * Produces a DB_Error object regarding the current problem
425 * @param int $errno if the error is being manually raised pass a
426 * DB_ERROR* constant here. If this isn't passed
427 * the error information gathered from the DBMS.
429 * @return object the DB_Error object
431 * @see DB_common::raiseError(),
432 * DB_mysqli::errorNative(), DB_common::errorCode()
434 public function mysqliRaiseError($errno = null)
436 if ($errno === null) {
437 if ($this->options['portability'] & DB_PORTABILITY_ERRORS) {
438 $this->errorcode_map[1022] = DB_ERROR_CONSTRAINT;
439 $this->errorcode_map[1048] = DB_ERROR_CONSTRAINT_NOT_NULL;
440 $this->errorcode_map[1062] = DB_ERROR_CONSTRAINT;
442 // Doing this in case mode changes during runtime.
443 $this->errorcode_map[1022] = DB_ERROR_ALREADY_EXISTS;
444 $this->errorcode_map[1048] = DB_ERROR_CONSTRAINT;
445 $this->errorcode_map[1062] = DB_ERROR_ALREADY_EXISTS;
447 $errno = $this->errorCode(mysqli_errno($this->connection));
449 return $this->raiseError(
454 @mysqli_errno($this->connection) . ' ** ' .
455 @mysqli_error($this->connection)
463 * Move the internal mysql result pointer to the next available result.
465 * This method has not been implemented yet.
467 * @param resource $result a valid sql result resource
471 public function nextResult($result)
480 * Places a row from the result set into the given array
482 * Formating of the array and the data therein are configurable.
483 * See DB_result::fetchInto() for more information.
485 * This method is not meant to be called directly. Use
486 * DB_result::fetchInto() instead. It can't be declared "protected"
487 * because DB_result is a separate object.
489 * @param resource $result the query result resource
490 * @param array $arr the referenced array to put the data in
491 * @param int $fetchmode how the resulting array should be indexed
492 * @param int $rownum the row number to fetch (0 = first row)
494 * @return mixed DB_OK on success, NULL when the end of a result set is
495 * reached or on failure
497 * @see DB_result::fetchInto()
499 public function fetchInto($result, &$arr, $fetchmode, $rownum = null)
501 if ($rownum !== null) {
502 if (!@mysqli_data_seek($result, $rownum)) {
506 if ($fetchmode & DB_FETCHMODE_ASSOC) {
507 $arr = @mysqli_fetch_array($result, MYSQLI_ASSOC);
508 if ($this->options['portability'] & DB_PORTABILITY_LOWERCASE && $arr) {
509 $arr = array_change_key_case($arr, CASE_LOWER);
512 $arr = @mysqli_fetch_row($result);
517 if ($this->options['portability'] & DB_PORTABILITY_RTRIM) {
519 * Even though this DBMS already trims output, we do this because
520 * a field might have intentional whitespace at the end that
521 * gets removed by DB_PORTABILITY_RTRIM under another driver.
523 $this->_rtrimArrayValues($arr);
525 if ($this->options['portability'] & DB_PORTABILITY_NULL_TO_EMPTY) {
526 $this->_convertNullArrayValuesToEmpty($arr);
535 * Deletes the result set and frees the memory occupied by the result set
537 * This method is not meant to be called directly. Use
538 * DB_result::free() instead. It can't be declared "protected"
539 * because DB_result is a separate object.
541 * @param resource $result PHP's query result resource
543 * @return bool TRUE on success, FALSE if $result is invalid
545 * @see DB_result::free()
547 public function freeResult($result)
549 if (!$result instanceof mysqli_result) {
552 mysqli_free_result($result);
560 * Gets the number of columns in a result set
562 * This method is not meant to be called directly. Use
563 * DB_result::numCols() instead. It can't be declared "protected"
564 * because DB_result is a separate object.
566 * @param resource $result PHP's query result resource
570 * @see DB_result::numCols()
572 public function numCols($result)
574 $cols = @mysqli_num_fields($result);
576 return $this->mysqliRaiseError();
585 * Gets the number of rows in a result set
587 * This method is not meant to be called directly. Use
588 * DB_result::numRows() instead. It can't be declared "protected"
589 * because DB_result is a separate object.
591 * @param resource $result PHP's query result resource
595 * @see DB_result::numRows()
597 public function numRows($result)
599 $rows = @mysqli_num_rows($result);
600 if ($rows === null) {
601 return $this->mysqliRaiseError();
610 * Enables or disables automatic commits
612 * @param bool $onoff true turns it on, false turns it off
614 * @return int DB_OK on success. A DB_Error object if the driver
615 * doesn't support auto-committing transactions.
617 public function autoCommit($onoff = false)
619 // XXX if $this->transaction_opcount > 0, we should probably
620 // issue a warning here.
621 $this->autocommit = $onoff ? true : false;
629 * Commits the current transaction
633 public function commit()
635 if ($this->transaction_opcount > 0) {
637 if (!@mysqli_select_db($this->connection, $this->_db)) {
638 return $this->mysqliRaiseError(DB_ERROR_NODBSELECTED);
641 $result = @mysqli_query($this->connection, 'COMMIT');
642 $result = @mysqli_query($this->connection, 'SET AUTOCOMMIT=1');
643 $this->transaction_opcount = 0;
645 return $this->mysqliRaiseError();
652 // {{{ affectedRows()
655 * Reverts the current transaction
659 public function rollback()
661 if ($this->transaction_opcount > 0) {
663 if (!@mysqli_select_db($this->connection, $this->_db)) {
664 return $this->mysqliRaiseError(DB_ERROR_NODBSELECTED);
667 $result = @mysqli_query($this->connection, 'ROLLBACK');
668 $result = @mysqli_query($this->connection, 'SET AUTOCOMMIT=1');
669 $this->transaction_opcount = 0;
671 return $this->mysqliRaiseError();
681 * Determines the number of rows affected by a data maniuplation query
683 * 0 is returned for queries that don't manipulate data.
685 * @return int the number of rows. A DB_Error object on failure.
687 public function affectedRows()
689 if ($this->_last_query_manip) {
690 return @mysqli_affected_rows($this->connection);
697 * Returns the next free id in a sequence
699 * @param string $seq_name name of the sequence
700 * @param boolean $ondemand when true, the seqence is automatically
701 * created if it does not exist
704 * A DB_Error object on failure.
706 * @see DB_common::nextID(), DB_common::getSequenceName(),
707 * DB_mysqli::createSequence(), DB_mysqli::dropSequence()
709 public function nextId($seq_name, $ondemand = true)
711 $seqname = $this->getSequenceName($seq_name);
714 $this->pushErrorHandling(PEAR_ERROR_RETURN);
715 $result = $this->query('UPDATE ' . $seqname
716 . ' SET id = LAST_INSERT_ID(id + 1)');
717 $this->popErrorHandling();
718 if ($result === DB_OK) {
720 $id = @mysqli_insert_id($this->connection);
726 // Sequence table must be empty for some reason,
727 // so fill it and return 1
728 // Obtain a user-level lock
729 $result = $this->getOne('SELECT GET_LOCK('
730 . "'${seqname}_lock', 10)");
731 if (DB::isError($result)) {
732 return $this->raiseError($result);
735 return $this->mysqliRaiseError(DB_ERROR_NOT_LOCKED);
738 // add the default value
739 $result = $this->query('REPLACE INTO ' . $seqname
740 . ' (id) VALUES (0)');
741 if (DB::isError($result)) {
742 return $this->raiseError($result);
746 $result = $this->getOne('SELECT RELEASE_LOCK('
747 . "'${seqname}_lock')");
748 if (DB::isError($result)) {
749 return $this->raiseError($result);
751 // We know what the result will be, so no need to try again
753 } elseif ($ondemand && DB::isError($result) &&
754 $result->getCode() == DB_ERROR_NOSUCHTABLE) {
755 // ONDEMAND TABLE CREATION
756 $result = $this->createSequence($seq_name);
758 // Since createSequence initializes the ID to be 1,
759 // we do not need to retrieve the ID again (or we will get 2)
760 if (DB::isError($result)) {
761 return $this->raiseError($result);
763 // First ID of a newly created sequence is 1
766 } elseif (DB::isError($result) &&
767 $result->getCode() == DB_ERROR_ALREADY_EXISTS) {
769 // see _BCsequence() comment
770 $result = $this->_BCsequence($seqname);
771 if (DB::isError($result)) {
772 return $this->raiseError($result);
778 return $this->raiseError($result);
782 // {{{ dropSequence()
785 * Creates a new sequence
787 * @param string $seq_name name of the new sequence
789 * @return int DB_OK on success. A DB_Error object on failure.
791 * @see DB_common::createSequence(), DB_common::getSequenceName(),
792 * DB_mysqli::nextID(), DB_mysqli::dropSequence()
794 public function createSequence($seq_name)
796 $seqname = $this->getSequenceName($seq_name);
797 $res = $this->query('CREATE TABLE ' . $seqname
798 . ' (id INTEGER UNSIGNED AUTO_INCREMENT NOT NULL,'
799 . ' PRIMARY KEY(id))');
800 if (DB::isError($res)) {
803 // insert yields value 1, nextId call will generate ID 2
804 return $this->query("INSERT INTO ${seqname} (id) VALUES (0)");
811 * Backwards compatibility with old sequence emulation implementation
812 * (clean up the dupes)
814 * @param string $seqname the sequence name to clean up
816 * @return bool|object
820 public function _BCsequence($seqname)
822 // Obtain a user-level lock... this will release any previous
823 // application locks, but unlike LOCK TABLES, it does not abort
824 // the current transaction and is much less frequently used.
825 $result = $this->getOne("SELECT GET_LOCK('${seqname}_lock',10)");
826 if (DB::isError($result)) {
830 // Failed to get the lock, can't do the conversion, bail
831 // with a DB_ERROR_NOT_LOCKED error
832 return $this->mysqliRaiseError(DB_ERROR_NOT_LOCKED);
835 $highest_id = $this->getOne("SELECT MAX(id) FROM ${seqname}");
836 if (DB::isError($highest_id)) {
840 // This should kill all rows except the highest
841 // We should probably do something if $highest_id isn't
842 // numeric, but I'm at a loss as how to handle that...
843 $result = $this->query('DELETE FROM ' . $seqname
844 . " WHERE id <> $highest_id");
845 if (DB::isError($result)) {
849 // If another thread has been waiting for this lock,
850 // it will go thru the above procedure, but will have no
852 $result = $this->getOne("SELECT RELEASE_LOCK('${seqname}_lock')");
853 if (DB::isError($result)) {
860 // {{{ quoteIdentifier()
865 * @param string $seq_name name of the sequence to be deleted
867 * @return int DB_OK on success. A DB_Error object on failure.
869 * @see DB_common::dropSequence(), DB_common::getSequenceName(),
870 * DB_mysql::nextID(), DB_mysql::createSequence()
872 public function dropSequence($seq_name)
874 return $this->query('DROP TABLE ' . $this->getSequenceName($seq_name));
878 // {{{ escapeSimple()
881 * Quotes a string so it can be safely used as a table or column name
882 * (WARNING: using names that require this is a REALLY BAD IDEA)
884 * WARNING: Older versions of MySQL can't handle the backtick
885 * character (<kbd>`</kbd>) in table or column names.
887 * @param string $str identifier name to be quoted
889 * @return string quoted identifier string
891 * @see DB_common::quoteIdentifier()
892 * @since Method available since Release 1.6.0
894 public function quoteIdentifier($str)
896 return '`' . str_replace('`', '``', $str) . '`';
900 // {{{ modifyLimitQuery()
903 * Escapes a string according to the current DBMS's standards
905 * @param string $str the string to be escaped
907 * @return string the escaped string
909 * @see DB_common::quoteSmart()
910 * @since Method available since Release 1.6.0
912 public function escapeSimple($str)
914 return @mysqli_real_escape_string($this->connection, $str);
918 // {{{ mysqliRaiseError()
921 * Adds LIMIT clauses to a query string according to current DBMS standards
923 * @param string $query the query to modify
924 * @param int $from the row to start to fetching (0 = the first row)
925 * @param int $count the numbers of rows to fetch
926 * @param mixed $params array, string or numeric data to be used in
927 * execution of the statement. Quantity of items
928 * passed must match quantity of placeholders in
929 * query: meaning 1 placeholder for non-array
930 * parameters or 1 placeholder per array element.
932 * @return string the query string with LIMIT clauses added
936 public function modifyLimitQuery($query, $from, $count, $params = array())
938 if (DB::isManip($query) || $this->_next_query_manip) {
939 return $query . " LIMIT $count";
941 return $query . " LIMIT $from, $count";
949 * Gets the DBMS' native error code produced by the last query
951 * @return int the DBMS' error code
953 public function errorNative()
955 return @mysqli_errno($this->connection);
962 * Returns information about a table or a result set
964 * @param object|string $result DB_result object from a query or a
965 * string containing the name of a table.
966 * While this also accepts a query result
967 * resource identifier, this behavior is
969 * @param int $mode a valid tableInfo mode
971 * @return array|object
972 * A DB_Error object on failure.
974 * @see DB_common::setOption()
976 public function tableInfo($result, $mode = null)
978 if (is_string($result)) {
979 // Fix for bug #11580.
981 if (!@mysqli_select_db($this->connection, $this->_db)) {
982 return $this->mysqliRaiseError(DB_ERROR_NODBSELECTED);
987 * Probably received a table name.
988 * Create a result resource identifier.
992 "SELECT * FROM $result LIMIT 0"
995 } elseif (isset($result->result)) {
997 * Probably received a result object.
998 * Extract the result resource identifier.
1000 $id = $result->result;
1001 $got_string = false;
1004 * Probably received a result resource identifier.
1006 * Deprecated. Here for compatibility only.
1009 $got_string = false;
1012 if (!is_object($id) || !is_a($id, 'mysqli_result')) {
1013 return $this->mysqliRaiseError(DB_ERROR_NEED_MORE_DATA);
1016 if ($this->options['portability'] & DB_PORTABILITY_LOWERCASE) {
1017 $case_func = 'strtolower';
1019 $case_func = 'strval';
1022 $count = @mysqli_num_fields($id);
1026 $res['num_fields'] = $count;
1029 for ($i = 0; $i < $count; $i++) {
1030 $tmp = @mysqli_fetch_field($id);
1033 foreach ($this->mysqli_flags as $const => $means) {
1034 if ($tmp->flags & $const) {
1035 $flags .= $means . ' ';
1039 $flags .= 'default_' . rawurlencode($tmp->def);
1041 $flags = trim($flags);
1044 'table' => $case_func($tmp->table),
1045 'name' => $case_func($tmp->name),
1046 'type' => isset($this->mysqli_types[$tmp->type])
1047 ? $this->mysqli_types[$tmp->type]
1049 // http://bugs.php.net/?id=36579
1050 // Doc Bug #36579: mysqli_fetch_field length handling
1051 // https://bugs.php.net/bug.php?id=62426
1052 // Bug #62426: mysqli_fetch_field_direct returns incorrect
1053 // length on UTF8 fields
1054 'len' => $tmp->length,
1058 if ($mode & DB_TABLEINFO_ORDER) {
1059 $res['order'][$res[$i]['name']] = $i;
1061 if ($mode & DB_TABLEINFO_ORDERTABLE) {
1062 $res['ordertable'][$res[$i]['table']][$res[$i]['name']] = $i;
1066 // free the result only if we were called on a table
1068 @mysqli_free_result($id);
1074 // {{{ getSpecialQuery()
1077 * Obtains the query string needed for listing a given type of objects
1079 * @param string $type the kind of objects you want to retrieve
1081 * @return string the SQL query string or null if the driver doesn't
1082 * support the object type requested
1085 * @see DB_common::getListOf()
1087 public function getSpecialQuery($type)
1091 return 'SHOW TABLES';
1093 return 'SELECT DISTINCT User FROM mysql.user';
1095 return 'SHOW DATABASES';
1101 public function getVersion()
1103 return mysqli_get_server_version($this->connection);