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.13
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_INVALID_VIEW
,
118 1365 => 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
137 * Should data manipulation queries be committed automatically?
141 var $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 var $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 var $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 var $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>$this->DB_common()</kbd>
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 (PEAR::isError($db)) {
277 * die($db->getMessage());
281 * @param array $dsn the data source name
282 * @param bool $persistent should the connection be persistent?
284 * @return int DB_OK on success. A DB_Error object on failure.
286 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(DB_ERROR_CONNECT_FAILED
,
341 return $this->raiseError(DB_ERROR_CONNECT_FAILED
,
347 if ($dsn['database']) {
348 $this->_db
= $dsn['database'];
358 * Disconnects from the database server
360 * @return bool TRUE on success, FALSE on failure
362 function disconnect()
364 $ret = @mysqli_close
($this->connection
);
365 $this->connection
= null;
373 * Sends a query to the database server
375 * @param string the SQL query string
377 * @return mixed + a PHP result resrouce for successful SELECT queries
378 * + the DB_OK constant for other successful queries
379 * + a DB_Error object on failure
381 function simpleQuery($query)
383 $ismanip = $this->_checkManip($query);
384 $this->last_query
= $query;
385 $query = $this->modifyQuery($query);
387 if (!@mysqli_select_db
($this->connection
, $this->_db
)) {
388 return $this->mysqliRaiseError(DB_ERROR_NODBSELECTED
);
391 if (!$this->autocommit
&& $ismanip) {
392 if ($this->transaction_opcount
== 0) {
393 $result = @mysqli_query
($this->connection
, 'SET AUTOCOMMIT=0');
394 $result = @mysqli_query
($this->connection
, 'BEGIN');
396 return $this->mysqliRaiseError();
399 $this->transaction_opcount++
;
401 $result = @mysqli_query
($this->connection
, $query);
403 return $this->mysqliRaiseError();
405 if (is_object($result)) {
415 * Move the internal mysql result pointer to the next available result.
417 * This method has not been implemented yet.
419 * @param resource $result a valid sql result resource
423 function nextResult($result)
432 * Places a row from the result set into the given array
434 * Formating of the array and the data therein are configurable.
435 * See DB_result::fetchInto() for more information.
437 * This method is not meant to be called directly. Use
438 * DB_result::fetchInto() instead. It can't be declared "protected"
439 * because DB_result is a separate object.
441 * @param resource $result the query result resource
442 * @param array $arr the referenced array to put the data in
443 * @param int $fetchmode how the resulting array should be indexed
444 * @param int $rownum the row number to fetch (0 = first row)
446 * @return mixed DB_OK on success, NULL when the end of a result set is
447 * reached or on failure
449 * @see DB_result::fetchInto()
451 function fetchInto($result, &$arr, $fetchmode, $rownum = null)
453 if ($rownum !== null) {
454 if (!@mysqli_data_seek
($result, $rownum)) {
458 if ($fetchmode & DB_FETCHMODE_ASSOC
) {
459 $arr = @mysqli_fetch_array
($result, MYSQLI_ASSOC
);
460 if ($this->options
['portability'] & DB_PORTABILITY_LOWERCASE
&& $arr) {
461 $arr = array_change_key_case($arr, CASE_LOWER
);
464 $arr = @mysqli_fetch_row
($result);
469 if ($this->options
['portability'] & DB_PORTABILITY_RTRIM
) {
471 * Even though this DBMS already trims output, we do this because
472 * a field might have intentional whitespace at the end that
473 * gets removed by DB_PORTABILITY_RTRIM under another driver.
475 $this->_rtrimArrayValues($arr);
477 if ($this->options
['portability'] & DB_PORTABILITY_NULL_TO_EMPTY
) {
478 $this->_convertNullArrayValuesToEmpty($arr);
487 * Deletes the result set and frees the memory occupied by the result set
489 * This method is not meant to be called directly. Use
490 * DB_result::free() instead. It can't be declared "protected"
491 * because DB_result is a separate object.
493 * @param resource $result PHP's query result resource
495 * @return bool TRUE on success, FALSE if $result is invalid
497 * @see DB_result::free()
499 function freeResult($result)
501 return is_resource($result) ?
mysqli_free_result($result) : false;
508 * Gets the number of columns in a result set
510 * This method is not meant to be called directly. Use
511 * DB_result::numCols() instead. It can't be declared "protected"
512 * because DB_result is a separate object.
514 * @param resource $result PHP's query result resource
516 * @return int the number of columns. A DB_Error object on failure.
518 * @see DB_result::numCols()
520 function numCols($result)
522 $cols = @mysqli_num_fields
($result);
524 return $this->mysqliRaiseError();
533 * Gets the number of rows in a result set
535 * This method is not meant to be called directly. Use
536 * DB_result::numRows() instead. It can't be declared "protected"
537 * because DB_result is a separate object.
539 * @param resource $result PHP's query result resource
541 * @return int the number of rows. A DB_Error object on failure.
543 * @see DB_result::numRows()
545 function numRows($result)
547 $rows = @mysqli_num_rows
($result);
548 if ($rows === null) {
549 return $this->mysqliRaiseError();
558 * Enables or disables automatic commits
560 * @param bool $onoff true turns it on, false turns it off
562 * @return int DB_OK on success. A DB_Error object if the driver
563 * doesn't support auto-committing transactions.
565 function autoCommit($onoff = false)
567 // XXX if $this->transaction_opcount > 0, we should probably
568 // issue a warning here.
569 $this->autocommit
= $onoff ?
true : false;
577 * Commits the current transaction
579 * @return int DB_OK on success. A DB_Error object on failure.
583 if ($this->transaction_opcount
> 0) {
585 if (!@mysqli_select_db
($this->connection
, $this->_db
)) {
586 return $this->mysqliRaiseError(DB_ERROR_NODBSELECTED
);
589 $result = @mysqli_query
($this->connection
, 'COMMIT');
590 $result = @mysqli_query
($this->connection
, 'SET AUTOCOMMIT=1');
591 $this->transaction_opcount
= 0;
593 return $this->mysqliRaiseError();
603 * Reverts the current transaction
605 * @return int DB_OK on success. A DB_Error object on failure.
609 if ($this->transaction_opcount
> 0) {
611 if (!@mysqli_select_db
($this->connection
, $this->_db
)) {
612 return $this->mysqliRaiseError(DB_ERROR_NODBSELECTED
);
615 $result = @mysqli_query
($this->connection
, 'ROLLBACK');
616 $result = @mysqli_query
($this->connection
, 'SET AUTOCOMMIT=1');
617 $this->transaction_opcount
= 0;
619 return $this->mysqliRaiseError();
626 // {{{ affectedRows()
629 * Determines the number of rows affected by a data maniuplation query
631 * 0 is returned for queries that don't manipulate data.
633 * @return int the number of rows. A DB_Error object on failure.
635 function affectedRows()
637 if ($this->_last_query_manip
) {
638 return @mysqli_affected_rows
($this->connection
);
648 * Returns the next free id in a sequence
650 * @param string $seq_name name of the sequence
651 * @param boolean $ondemand when true, the seqence is automatically
652 * created if it does not exist
654 * @return int the next id number in the sequence.
655 * A DB_Error object on failure.
657 * @see DB_common::nextID(), DB_common::getSequenceName(),
658 * DB_mysqli::createSequence(), DB_mysqli::dropSequence()
660 function nextId($seq_name, $ondemand = true)
662 $seqname = $this->getSequenceName($seq_name);
665 $this->pushErrorHandling(PEAR_ERROR_RETURN
);
666 $result = $this->query('UPDATE ' . $seqname
667 . ' SET id = LAST_INSERT_ID(id + 1)');
668 $this->popErrorHandling();
669 if ($result === DB_OK
) {
671 $id = @mysqli_insert_id
($this->connection
);
677 // Sequence table must be empty for some reason,
678 // so fill it and return 1
679 // Obtain a user-level lock
680 $result = $this->getOne('SELECT GET_LOCK('
681 . "'${seqname}_lock', 10)");
682 if (DB
::isError($result)) {
683 return $this->raiseError($result);
686 return $this->mysqliRaiseError(DB_ERROR_NOT_LOCKED
);
689 // add the default value
690 $result = $this->query('REPLACE INTO ' . $seqname
691 . ' (id) VALUES (0)');
692 if (DB
::isError($result)) {
693 return $this->raiseError($result);
697 $result = $this->getOne('SELECT RELEASE_LOCK('
698 . "'${seqname}_lock')");
699 if (DB
::isError($result)) {
700 return $this->raiseError($result);
702 // We know what the result will be, so no need to try again
705 } elseif ($ondemand && DB
::isError($result) &&
706 $result->getCode() == DB_ERROR_NOSUCHTABLE
)
708 // ONDEMAND TABLE CREATION
709 $result = $this->createSequence($seq_name);
711 // Since createSequence initializes the ID to be 1,
712 // we do not need to retrieve the ID again (or we will get 2)
713 if (DB
::isError($result)) {
714 return $this->raiseError($result);
716 // First ID of a newly created sequence is 1
720 } elseif (DB
::isError($result) &&
721 $result->getCode() == DB_ERROR_ALREADY_EXISTS
)
724 // see _BCsequence() comment
725 $result = $this->_BCsequence($seqname);
726 if (DB
::isError($result)) {
727 return $this->raiseError($result);
733 return $this->raiseError($result);
737 * Creates a new sequence
739 * @param string $seq_name name of the new sequence
741 * @return int DB_OK on success. A DB_Error object on failure.
743 * @see DB_common::createSequence(), DB_common::getSequenceName(),
744 * DB_mysqli::nextID(), DB_mysqli::dropSequence()
746 function createSequence($seq_name)
748 $seqname = $this->getSequenceName($seq_name);
749 $res = $this->query('CREATE TABLE ' . $seqname
750 . ' (id INTEGER UNSIGNED AUTO_INCREMENT NOT NULL,'
751 . ' PRIMARY KEY(id))');
752 if (DB
::isError($res)) {
755 // insert yields value 1, nextId call will generate ID 2
756 return $this->query("INSERT INTO ${seqname} (id) VALUES (0)");
760 // {{{ dropSequence()
765 * @param string $seq_name name of the sequence to be deleted
767 * @return int DB_OK on success. A DB_Error object on failure.
769 * @see DB_common::dropSequence(), DB_common::getSequenceName(),
770 * DB_mysql::nextID(), DB_mysql::createSequence()
772 function dropSequence($seq_name)
774 return $this->query('DROP TABLE ' . $this->getSequenceName($seq_name));
781 * Backwards compatibility with old sequence emulation implementation
782 * (clean up the dupes)
784 * @param string $seqname the sequence name to clean up
786 * @return bool true on success. A DB_Error object on failure.
790 function _BCsequence($seqname)
792 // Obtain a user-level lock... this will release any previous
793 // application locks, but unlike LOCK TABLES, it does not abort
794 // the current transaction and is much less frequently used.
795 $result = $this->getOne("SELECT GET_LOCK('${seqname}_lock',10)");
796 if (DB
::isError($result)) {
800 // Failed to get the lock, can't do the conversion, bail
801 // with a DB_ERROR_NOT_LOCKED error
802 return $this->mysqliRaiseError(DB_ERROR_NOT_LOCKED
);
805 $highest_id = $this->getOne("SELECT MAX(id) FROM ${seqname}");
806 if (DB
::isError($highest_id)) {
810 // This should kill all rows except the highest
811 // We should probably do something if $highest_id isn't
812 // numeric, but I'm at a loss as how to handle that...
813 $result = $this->query('DELETE FROM ' . $seqname
814 . " WHERE id <> $highest_id");
815 if (DB
::isError($result)) {
819 // If another thread has been waiting for this lock,
820 // it will go thru the above procedure, but will have no
822 $result = $this->getOne("SELECT RELEASE_LOCK('${seqname}_lock')");
823 if (DB
::isError($result)) {
830 // {{{ quoteIdentifier()
833 * Quotes a string so it can be safely used as a table or column name
834 * (WARNING: using names that require this is a REALLY BAD IDEA)
836 * WARNING: Older versions of MySQL can't handle the backtick
837 * character (<kbd>`</kbd>) in table or column names.
839 * @param string $str identifier name to be quoted
841 * @return string quoted identifier string
843 * @see DB_common::quoteIdentifier()
844 * @since Method available since Release 1.6.0
846 function quoteIdentifier($str)
848 return '`' . str_replace('`', '``', $str) . '`';
852 // {{{ escapeSimple()
855 * Escapes a string according to the current DBMS's standards
857 * @param string $str the string to be escaped
859 * @return string the escaped string
861 * @see DB_common::quoteSmart()
862 * @since Method available since Release 1.6.0
864 function escapeSimple($str)
866 return @mysqli_real_escape_string
($this->connection
, $str);
870 // {{{ modifyLimitQuery()
873 * Adds LIMIT clauses to a query string according to current DBMS standards
875 * @param string $query the query to modify
876 * @param int $from the row to start to fetching (0 = the first row)
877 * @param int $count the numbers of rows to fetch
878 * @param mixed $params array, string or numeric data to be used in
879 * execution of the statement. Quantity of items
880 * passed must match quantity of placeholders in
881 * query: meaning 1 placeholder for non-array
882 * parameters or 1 placeholder per array element.
884 * @return string the query string with LIMIT clauses added
888 function modifyLimitQuery($query, $from, $count, $params = array())
890 if (DB
::isManip($query) ||
$this->_next_query_manip
) {
891 return $query . " LIMIT $count";
893 return $query . " LIMIT $from, $count";
898 // {{{ mysqliRaiseError()
901 * Produces a DB_Error object regarding the current problem
903 * @param int $errno if the error is being manually raised pass a
904 * DB_ERROR* constant here. If this isn't passed
905 * the error information gathered from the DBMS.
907 * @return object the DB_Error object
909 * @see DB_common::raiseError(),
910 * DB_mysqli::errorNative(), DB_common::errorCode()
912 function mysqliRaiseError($errno = null)
914 if ($errno === null) {
915 if ($this->options
['portability'] & DB_PORTABILITY_ERRORS
) {
916 $this->errorcode_map
[1022] = DB_ERROR_CONSTRAINT
;
917 $this->errorcode_map
[1048] = DB_ERROR_CONSTRAINT_NOT_NULL
;
918 $this->errorcode_map
[1062] = DB_ERROR_CONSTRAINT
;
920 // Doing this in case mode changes during runtime.
921 $this->errorcode_map
[1022] = DB_ERROR_ALREADY_EXISTS
;
922 $this->errorcode_map
[1048] = DB_ERROR_CONSTRAINT
;
923 $this->errorcode_map
[1062] = DB_ERROR_ALREADY_EXISTS
;
925 $errno = $this->errorCode(mysqli_errno($this->connection
));
927 return $this->raiseError($errno, null, null, null,
928 @mysqli_errno
($this->connection
) . ' ** ' .
929 @mysqli_error
($this->connection
));
936 * Gets the DBMS' native error code produced by the last query
938 * @return int the DBMS' error code
940 function errorNative()
942 return @mysqli_errno
($this->connection
);
949 * Returns information about a table or a result set
951 * @param object|string $result DB_result object from a query or a
952 * string containing the name of a table.
953 * While this also accepts a query result
954 * resource identifier, this behavior is
956 * @param int $mode a valid tableInfo mode
958 * @return array an associative array with the information requested.
959 * A DB_Error object on failure.
961 * @see DB_common::setOption()
963 function tableInfo($result, $mode = null)
965 if (is_string($result)) {
966 // Fix for bug #11580.
968 if (!@mysqli_select_db
($this->connection
, $this->_db
)) {
969 return $this->mysqliRaiseError(DB_ERROR_NODBSELECTED
);
974 * Probably received a table name.
975 * Create a result resource identifier.
977 $id = @mysqli_query
($this->connection
,
978 "SELECT * FROM $result LIMIT 0");
980 } elseif (isset($result->result
)) {
982 * Probably received a result object.
983 * Extract the result resource identifier.
985 $id = $result->result
;
989 * Probably received a result resource identifier.
991 * Deprecated. Here for compatibility only.
997 if (!is_a($id, 'mysqli_result')) {
998 return $this->mysqliRaiseError(DB_ERROR_NEED_MORE_DATA
);
1001 if ($this->options
['portability'] & DB_PORTABILITY_LOWERCASE
) {
1002 $case_func = 'strtolower';
1004 $case_func = 'strval';
1007 $count = @mysqli_num_fields
($id);
1011 $res['num_fields'] = $count;
1014 for ($i = 0; $i < $count; $i++
) {
1015 $tmp = @mysqli_fetch_field
($id);
1018 foreach ($this->mysqli_flags
as $const => $means) {
1019 if ($tmp->flags
& $const) {
1020 $flags .= $means . ' ';
1024 $flags .= 'default_' . rawurlencode($tmp->def
);
1026 $flags = trim($flags);
1029 'table' => $case_func($tmp->table
),
1030 'name' => $case_func($tmp->name
),
1031 'type' => isset($this->mysqli_types
[$tmp->type
])
1032 ?
$this->mysqli_types
[$tmp->type
]
1034 // http://bugs.php.net/?id=36579
1035 'len' => $tmp->length
,
1039 if ($mode & DB_TABLEINFO_ORDER
) {
1040 $res['order'][$res[$i]['name']] = $i;
1042 if ($mode & DB_TABLEINFO_ORDERTABLE
) {
1043 $res['ordertable'][$res[$i]['table']][$res[$i]['name']] = $i;
1047 // free the result only if we were called on a table
1049 @mysqli_free_result
($id);
1055 // {{{ getSpecialQuery()
1058 * Obtains the query string needed for listing a given type of objects
1060 * @param string $type the kind of objects you want to retrieve
1062 * @return string the SQL query string or null if the driver doesn't
1063 * support the object type requested
1066 * @see DB_common::getListOf()
1068 function getSpecialQuery($type)
1072 return 'SHOW TABLES';
1074 return 'SELECT DISTINCT User FROM mysql.user';
1076 return 'SHOW DATABASES';