📄 mysqli.php
字号:
<?php/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: *//** * The PEAR DB driver for PHP's mysqli extension * for interacting with MySQL databases * * PHP versions 4 and 5 * * LICENSE: This source file is subject to version 3.0 of the PHP license * that is available through the world-wide-web at the following URI: * http://www.php.net/license/3_0.txt. If you did not receive a copy of * the PHP License and are unable to obtain it through the web, please * send a note to license@php.net so we can mail you a copy immediately. * * @category Database * @package DB * @author Daniel Convissor <danielc@php.net> * @copyright 1997-2005 The PHP Group * @license http://www.php.net/license/3_0.txt PHP License 3.0 * @version CVS: $Id: mysqli.php,v 1.69 2005/03/04 23:12:36 danielc Exp $ * @link http://pear.php.net/package/DB *//** * Obtain the DB_common class so it can be extended from */require_once 'DB/common.php';/** * The methods PEAR DB uses to interact with PHP's mysqli extension * for interacting with MySQL databases * * This is for MySQL versions 4.1 and above. Requires PHP 5. * * Note that persistent connections no longer exist. * * These methods overload the ones declared in DB_common. * * @category Database * @package DB * @author Daniel Convissor <danielc@php.net> * @copyright 1997-2005 The PHP Group * @license http://www.php.net/license/3_0.txt PHP License 3.0 * @version Release: 1.7.6 * @link http://pear.php.net/package/DB * @since Class functional since Release 1.6.3 */class DB_mysqli extends DB_common{ // {{{ properties /** * The DB driver type (mysql, oci8, odbc, etc.) * @var string */ var $phptype = 'mysqli'; /** * The database syntax variant to be used (db2, access, etc.), if any * @var string */ var $dbsyntax = 'mysqli'; /** * The capabilities of this DB implementation * * The 'new_link' element contains the PHP version that first provided * new_link support for this DBMS. Contains false if it's unsupported. * * Meaning of the 'limit' element: * + 'emulate' = emulate with fetch row by number * + 'alter' = alter the query * + false = skip rows * * @var array */ var $features = array( 'limit' => 'alter', 'new_link' => false, 'numrows' => true, 'pconnect' => false, 'prepare' => false, 'ssl' => true, 'transactions' => true, ); /** * A mapping of native error codes to DB error codes * @var array */ var $errorcode_map = array( 1004 => DB_ERROR_CANNOT_CREATE, 1005 => DB_ERROR_CANNOT_CREATE, 1006 => DB_ERROR_CANNOT_CREATE, 1007 => DB_ERROR_ALREADY_EXISTS, 1008 => DB_ERROR_CANNOT_DROP, 1022 => DB_ERROR_ALREADY_EXISTS, 1044 => DB_ERROR_ACCESS_VIOLATION, 1046 => DB_ERROR_NODBSELECTED, 1048 => DB_ERROR_CONSTRAINT, 1049 => DB_ERROR_NOSUCHDB, 1050 => DB_ERROR_ALREADY_EXISTS, 1051 => DB_ERROR_NOSUCHTABLE, 1054 => DB_ERROR_NOSUCHFIELD, 1061 => DB_ERROR_ALREADY_EXISTS, 1062 => DB_ERROR_ALREADY_EXISTS, 1064 => DB_ERROR_SYNTAX, 1091 => DB_ERROR_NOT_FOUND, 1100 => DB_ERROR_NOT_LOCKED, 1136 => DB_ERROR_VALUE_COUNT_ON_ROW, 1142 => DB_ERROR_ACCESS_VIOLATION, 1146 => DB_ERROR_NOSUCHTABLE, 1216 => DB_ERROR_CONSTRAINT, 1217 => DB_ERROR_CONSTRAINT, ); /** * The raw database connection created by PHP * @var resource */ var $connection; /** * The DSN information for connecting to a database * @var array */ var $dsn = array(); /** * Should data manipulation queries be committed automatically? * @var bool * @access private */ var $autocommit = true; /** * The quantity of transactions begun * * {@internal While this is private, it can't actually be designated * private in PHP 5 because it is directly accessed in the test suite.}} * * @var integer * @access private */ var $transaction_opcount = 0; /** * The database specified in the DSN * * It's a fix to allow calls to different databases in the same script. * * @var string * @access private */ var $_db = ''; /** * Array for converting MYSQLI_*_FLAG constants to text values * @var array * @access public * @since Property available since Release 1.6.5 */ var $mysqli_flags = array( MYSQLI_NOT_NULL_FLAG => 'not_null', MYSQLI_PRI_KEY_FLAG => 'primary_key', MYSQLI_UNIQUE_KEY_FLAG => 'unique_key', MYSQLI_MULTIPLE_KEY_FLAG => 'multiple_key', MYSQLI_BLOB_FLAG => 'blob', MYSQLI_UNSIGNED_FLAG => 'unsigned', MYSQLI_ZEROFILL_FLAG => 'zerofill', MYSQLI_AUTO_INCREMENT_FLAG => 'auto_increment', MYSQLI_TIMESTAMP_FLAG => 'timestamp', MYSQLI_SET_FLAG => 'set', // MYSQLI_NUM_FLAG => 'numeric', // unnecessary // MYSQLI_PART_KEY_FLAG => 'multiple_key', // duplicatvie MYSQLI_GROUP_FLAG => 'group_by' ); /** * Array for converting MYSQLI_TYPE_* constants to text values * @var array * @access public * @since Property available since Release 1.6.5 */ var $mysqli_types = array( MYSQLI_TYPE_DECIMAL => 'decimal', MYSQLI_TYPE_TINY => 'tinyint', MYSQLI_TYPE_SHORT => 'int', MYSQLI_TYPE_LONG => 'int', MYSQLI_TYPE_FLOAT => 'float', MYSQLI_TYPE_DOUBLE => 'double', // MYSQLI_TYPE_NULL => 'DEFAULT NULL', // let flags handle it MYSQLI_TYPE_TIMESTAMP => 'timestamp', MYSQLI_TYPE_LONGLONG => 'bigint', MYSQLI_TYPE_INT24 => 'mediumint', MYSQLI_TYPE_DATE => 'date', MYSQLI_TYPE_TIME => 'time', MYSQLI_TYPE_DATETIME => 'datetime', MYSQLI_TYPE_YEAR => 'year', MYSQLI_TYPE_NEWDATE => 'date', MYSQLI_TYPE_ENUM => 'enum', MYSQLI_TYPE_SET => 'set', MYSQLI_TYPE_TINY_BLOB => 'tinyblob', MYSQLI_TYPE_MEDIUM_BLOB => 'mediumblob', MYSQLI_TYPE_LONG_BLOB => 'longblob', MYSQLI_TYPE_BLOB => 'blob', MYSQLI_TYPE_VAR_STRING => 'varchar', MYSQLI_TYPE_STRING => 'char', MYSQLI_TYPE_GEOMETRY => 'geometry', ); // }}} // {{{ constructor /** * This constructor calls <kbd>$this->DB_common()</kbd> * * @return void */ function DB_mysqli() { $this->DB_common(); } // }}} // {{{ connect() /** * Connect to the database server, log in and open the database * * Don't call this method directly. Use DB::connect() instead. * * PEAR DB's mysqli driver supports the following extra DSN options: * + When the 'ssl' $option passed to DB::connect() is true: * + key The path to the key file. * + cert The path to the certificate file. * + ca The path to the certificate authority file. * + capath The path to a directory that contains trusted SSL * CA certificates in pem format. * + cipher The list of allowable ciphers for SSL encryption. * * Example of how to connect using SSL: * <code> * require_once 'DB.php'; * * $dsn = array( * 'phptype' => 'mysqli', * 'username' => 'someuser', * 'password' => 'apasswd', * 'hostspec' => 'localhost', * 'database' => 'thedb', * 'key' => 'client-key.pem', * 'cert' => 'client-cert.pem', * 'ca' => 'cacert.pem', * 'capath' => '/path/to/ca/dir', * 'cipher' => 'AES', * ); * * $options = array( * 'ssl' => true, * ); * * $db =& DB::connect($dsn, $options); * if (PEAR::isError($db)) { * die($db->getMessage()); * } * </code> * * @param array $dsn the data source name * @param bool $persistent should the connection be persistent? * * @return int DB_OK on success. A DB_Error object on failure. */ function connect($dsn, $persistent = false) { if (!PEAR::loadExtension('mysqli')) { return $this->raiseError(DB_ERROR_EXTENSION_NOT_FOUND); } $this->dsn = $dsn; if ($dsn['dbsyntax']) { $this->dbsyntax = $dsn['dbsyntax']; } $ini = ini_get('track_errors'); ini_set('track_errors', 1); $php_errormsg = ''; if ($this->getOption('ssl') === true) { $init = mysqli_init(); mysqli_ssl_set( $init, empty($dsn['key']) ? null : $dsn['key'], empty($dsn['cert']) ? null : $dsn['cert'], empty($dsn['ca']) ? null : $dsn['ca'], empty($dsn['capath']) ? null : $dsn['capath'], empty($dsn['cipher']) ? null : $dsn['cipher'] ); if ($this->connection = @mysqli_real_connect( $init, $dsn['hostspec'], $dsn['username'], $dsn['password'], $dsn['database'], $dsn['port'], $dsn['socket'])) { $this->connection = $init; } } else { $this->connection = @mysqli_connect( $dsn['hostspec'], $dsn['username'], $dsn['password'], $dsn['database'], $dsn['port'], $dsn['socket'] ); } ini_set('track_errors', $ini); if (!$this->connection) { if (($err = @mysqli_connect_error()) != '') { return $this->raiseError(DB_ERROR_CONNECT_FAILED, null, null, null, $err); } else { return $this->raiseError(DB_ERROR_CONNECT_FAILED, null, null, null, $php_errormsg); } } if ($dsn['database']) { $this->_db = $dsn['database']; } return DB_OK; } // }}} // {{{ disconnect() /** * Disconnects from the database server * * @return bool TRUE on success, FALSE on failure */ function disconnect() { $ret = @mysqli_close($this->connection); $this->connection = null; return $ret; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -