本文整理汇总了PHP中mysqli_options函数的典型用法代码示例。如果您正苦于以下问题:PHP mysqli_options函数的具体用法?PHP mysqli_options怎么用?PHP mysqli_options使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了mysqli_options函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: PMA_DBI_connect
/**
* connects to the database server
*
* @uses $GLOBALS['cfg']['Server']
* @uses PMA_auth_fails()
* @uses PMA_DBI_postConnect()
* @uses MYSQLI_CLIENT_COMPRESS
* @uses MYSQLI_OPT_LOCAL_INFILE
* @uses strtolower()
* @uses mysqli_init()
* @uses mysqli_options()
* @uses mysqli_real_connect()
* @uses defined()
* @param string $user mysql user name
* @param string $password mysql user password
* @param boolean $is_controluser
* @return mixed false on error or a mysqli object on success
*/
function PMA_DBI_connect($user, $password, $is_controluser = false)
{
$server_port = empty($GLOBALS['cfg']['Server']['port']) ? false : (int) $GLOBALS['cfg']['Server']['port'];
if (strtolower($GLOBALS['cfg']['Server']['connect_type']) == 'tcp') {
$GLOBALS['cfg']['Server']['socket'] = '';
}
// NULL enables connection to the default socket
$server_socket = empty($GLOBALS['cfg']['Server']['socket']) ? null : $GLOBALS['cfg']['Server']['socket'];
$link = mysqli_init();
mysqli_options($link, MYSQLI_OPT_LOCAL_INFILE, true);
$client_flags = 0;
/* Optionally compress connection */
if ($GLOBALS['cfg']['Server']['compress'] && defined('MYSQLI_CLIENT_COMPRESS')) {
$client_flags |= MYSQLI_CLIENT_COMPRESS;
}
/* Optionally enable SSL */
if ($GLOBALS['cfg']['Server']['ssl'] && defined('MYSQLI_CLIENT_SSL')) {
$client_flags |= MYSQLI_CLIENT_SSL;
}
$return_value = @mysqli_real_connect($link, $GLOBALS['cfg']['Server']['host'], $user, $password, false, $server_port, $server_socket, $client_flags);
// Retry with empty password if we're allowed to
if ($return_value == false && isset($cfg['Server']['nopassword']) && $cfg['Server']['nopassword'] && !$is_controluser) {
$return_value = @mysqli_real_connect($link, $GLOBALS['cfg']['Server']['host'], $user, '', false, $server_port, $server_socket, $client_flags);
}
if ($return_value == false) {
PMA_auth_fails();
}
// end if
PMA_DBI_postConnect($link, $is_controluser);
return $link;
}
示例2: _connect
function _connect($argHostname = NULL, $argUsername = NULL, $argPassword = NULL, $argDatabasename = NULL, $persist = false)
{
if (!extension_loaded("mysqli")) {
return null;
}
$this->_connectionID = @mysqli_init();
if (is_null($this->_connectionID)) {
// mysqli_init only fails if insufficient memory
if ($this->debug) {
ADOConnection::outp("mysqli_init() failed : " . $this->ErrorMsg());
}
return false;
}
/*
I suggest a simple fix which would enable adodb and mysqli driver to
read connection options from the standard mysql configuration file
/etc/my.cnf - "Bastien Duclaux" <bduclaux#yahoo.com>
*/
foreach ($this->optionFlags as $arr) {
mysqli_options($this->_connectionID, $arr[0], $arr[1]);
}
#if (!empty($this->port)) $argHostname .= ":".$this->port;
$ok = mysqli_real_connect($this->_connectionID, $argHostname, $argUsername, $argPassword, $argDatabasename, $this->port, $this->socket, $this->clientFlags);
if ($ok) {
if ($argDatabasename) {
return $this->SelectDB($argDatabasename);
}
return true;
} else {
if ($this->debug) {
ADOConnection::outp("Could't connect : " . $this->ErrorMsg());
}
return false;
}
}
示例3: db_connect
/**
* Initialize database connection(s)
*
* Connects to the specified master database server, and also to the slave server if it is specified
*
* @param string Name of the database server - should be either 'localhost' or an IP address
* @param integer Port of the database server - usually 3306
* @param string Username to connect to the database server
* @param string Password associated with the username for the database server
* @param string Persistent Connections - Not supported with MySQLi
* @param string Configuration file from config.php.ini (my.ini / my.cnf)
* @param string Mysqli Connection Charset PHP 5.1.0+ or 5.0.5+ / MySQL 4.1.13+ or MySQL 5.1.10+ Only
*
* @return object Mysqli Resource
*/
function db_connect($servername, $port, $username, $password, $usepconnect, $configfile = '', $charset = '')
{
set_error_handler(array($this, 'catch_db_error'));
$link = mysqli_init();
# Set Options Connection Options
if (!empty($configfile)) {
mysqli_options($link, MYSQLI_READ_DEFAULT_FILE, $configfile);
}
try {
// this will execute at most 5 times, see catch_db_error()
do {
$connect = $this->functions['connect']($link, $servername, $username, $password, '', $port);
} while ($connect == false and $this->reporterror);
} catch (Exception $e) {
restore_error_handler();
throw $e;
}
restore_error_handler();
if (!empty($charset)) {
if (function_exists('mysqli_set_charset')) {
mysqli_set_charset($link, $charset);
} else {
$this->sql = "SET NAMES {$charset}";
$this->execute_query(true, $link);
}
}
return !$connect ? false : $link;
}
示例4: doConnect
/**
* 连接数据库
*
* @param array $config
* @return string 返回连接的id
*/
public function doConnect(array &$config)
{
try {
if (empty($persistent)) {
$resource = \mysqli_init();
\mysqli_options($resource, \MYSQLI_OPT_CONNECT_TIMEOUT, 3);
if (isset($this->config['option']) && is_array($this->config['option'])) {
foreach ($this->config['option'] as $k => $v) {
\mysqli_options($resource, $k, $v);
}
}
\mysqli_real_connect($resource, $config['hostname'], $config['username'], $config['password'], $config['database'], $config['port'], null, \MYSQLI_CLIENT_COMPRESS);
} else {
$resource = new \mysqli($config['hostname'], $config['username'], $config['password'], $config['database'], $config['port']);
}
# 设置语言
$resource->set_charset($this->config['charset']);
return $resource;
} catch (Exception $e) {
if (2 === $e->getCode() && preg_match('#(Unknown database|Access denied for user)#i', $e->getMessage(), $m)) {
# 指定的库不存在,直接返回
$lastError = strtolower($m[1]) === 'unknown database' ? __('The mysql database does not exist') : __('The mysql database account or password error');
} else {
$lastError = $e->getMessage();
}
$lastErrorCode = $e->getCode();
}
throw new Exception($lastError, $lastErrorCode);
}
示例5: __construct
/**
* @param object $link
* @param array $options
*/
public function __construct($link = false, $options = array())
{
foreach ($options as $key => $value) {
$this->{$key} = $value;
}
if ($link) {
$this->link = $link;
} else {
if (!empty($options)) {
if (isset($this->host)) {
$this->hostname = $this->host;
}
if (isset($this->dbname)) {
$this->database = $this->dbname;
}
//$this->link = @mysqli_connect($this->hostname, $this->username, $this->password, $this->database);
$this->link = mysqli_init();
mysqli_options($this->link, MYSQLI_OPT_CONNECT_TIMEOUT, 1);
if (@mysqli_real_connect($this->link, $this->hostname, $this->username, $this->password, $this->database)) {
$names = "SET NAMES '" . $this->charset . "';";
mysqli_query($this->link, $names);
$charset = "SET CHARSET '" . $this->charset . "';";
mysqli_query($this->link, $charset);
} else {
$this->link = false;
}
}
}
}
示例6: connect
/**
*/
function connect()
{
$this->db_connect_id = mysqli_init();
if (!$this->db_connect_id) {
$this->_connect_error = 'cannot_connect_to_server';
$this->db_connect_id = null;
return false;
}
foreach ((array) $this->INI_OPTS as $ini_name => $ini_val) {
ini_set($ini_name, $ini_val);
}
if (!$this->ON_BEFORE_CONNECT) {
$this->ON_BEFORE_CONNECT[] = function () {
return $this->_on_before_connect_default();
};
}
foreach ((array) $this->ON_BEFORE_CONNECT as $func) {
if (is_callable($func)) {
$func($this);
}
}
if ($this->params['socket']) {
$connect_host = $this->params['socket'];
} else {
$connect_port = $this->params['port'] && $this->params['port'] != $this->DEF_PORT ? $this->params['port'] : '';
$connect_host = ($this->params['persist'] ? 'p:' : '') . $this->params['host'] . ($connect_port ? ':' . $connect_port : '');
}
mysqli_options($this->db_connect_id, MYSQLI_OPT_CONNECT_TIMEOUT, $this->CONNECT_TIMEOUT);
$is_connected = mysqli_real_connect($this->db_connect_id, $this->params['host'], $this->params['user'], $this->params['pswd'], '', $this->params['port'], $this->params['socket'], $this->params['ssl'] ? MYSQLI_CLIENT_SSL : 0);
if (!$is_connected) {
$this->_connect_error = 'cannot_connect_to_server';
return false;
} else {
foreach ((array) $this->SQL_AFTER_CONNECT as $sql) {
$this->query($sql);
}
}
if ($this->params['name'] != '') {
$dbselect = $this->select_db($this->params['name']);
// Try to create database, if not exists and if allowed
if (!$dbselect && $this->params['allow_auto_create_db'] && preg_match('/^[a-z0-9][a-z0-9_]+[a-z0-9]$/i', $this->params['name'])) {
$res = $this->query('CREATE DATABASE IF NOT EXISTS ' . $this->params['name']);
if ($res) {
$dbselect = $this->select_db($this->params['name']);
}
}
if (!$dbselect) {
$this->_connect_error = 'cannot_select_db';
}
foreach ((array) $this->ON_AFTER_CONNECT as $func) {
if (is_callable($func)) {
$func($this, $dbselect);
}
}
return $dbselect;
}
}
示例7: getConnection
public static function getConnection($index = DB_SLAVE)
{
$index = !empty($index) ? $index : DB_SLAVE;
if (empty(self::$instance[$index]) || empty(self::$instance[$index]->connection->client_info) || !is_object(self::$instance[$index])) {
self::$instance[$index] = new Database($index);
mysqli_options(self::$instance[$index], MYSQLI_OPT_CONNECT_TIMEOUT, 10);
}
return self::$instance[$index];
}
示例8: PMA_DBI_connect
/**
* connects to the database server
*
* @uses $GLOBALS['cfg']['Server']
* @uses PMA_auth_fails()
* @uses PMA_DBI_postConnect()
* @uses MYSQLI_CLIENT_COMPRESS
* @uses MYSQLI_OPT_LOCAL_INFILE
* @uses strtolower()
* @uses mysqli_init()
* @uses mysqli_options()
* @uses mysqli_real_connect()
* @uses defined()
* @param string $user mysql user name
* @param string $password mysql user password
* @param boolean $is_controluser
* @param array $server host/port/socket
* @param boolean $auxiliary_connection (when true, don't go back to login if connection fails)
* @return mixed false on error or a mysqli object on success
*/
function PMA_DBI_connect($user, $password, $is_controluser = false, $server = null, $auxiliary_connection = false)
{
if ($server) {
$server_port = empty($server['port']) ? false : (int) $server['port'];
$server_socket = empty($server['socket']) ? '' : $server['socket'];
$server['host'] = empty($server['host']) ? 'localhost' : $server['host'];
} else {
$server_port = empty($GLOBALS['cfg']['Server']['port']) ? false : (int) $GLOBALS['cfg']['Server']['port'];
$server_socket = empty($GLOBALS['cfg']['Server']['socket']) ? null : $GLOBALS['cfg']['Server']['socket'];
}
if (strtolower($GLOBALS['cfg']['Server']['connect_type']) == 'tcp') {
$GLOBALS['cfg']['Server']['socket'] = '';
}
// NULL enables connection to the default socket
$link = mysqli_init();
mysqli_options($link, MYSQLI_OPT_LOCAL_INFILE, true);
$client_flags = 0;
/* Optionally compress connection */
if ($GLOBALS['cfg']['Server']['compress'] && defined('MYSQLI_CLIENT_COMPRESS')) {
$client_flags |= MYSQLI_CLIENT_COMPRESS;
}
/* Optionally enable SSL */
if ($GLOBALS['cfg']['Server']['ssl'] && defined('MYSQLI_CLIENT_SSL')) {
$client_flags |= MYSQLI_CLIENT_SSL;
}
if (!$server) {
$return_value = @mysqli_real_connect($link, $GLOBALS['cfg']['Server']['host'], $user, $password, false, $server_port, $server_socket, $client_flags);
// Retry with empty password if we're allowed to
if ($return_value == false && isset($GLOBALS['cfg']['Server']['nopassword']) && $GLOBALS['cfg']['Server']['nopassword'] && !$is_controluser) {
$return_value = @mysqli_real_connect($link, $GLOBALS['cfg']['Server']['host'], $user, '', false, $server_port, $server_socket, $client_flags);
}
} else {
$return_value = @mysqli_real_connect($link, $server['host'], $user, $password, false, $server_port, $server_socket);
}
if ($return_value == false) {
if ($is_controluser) {
trigger_error(__('Connection for controluser as defined in your configuration failed.'), E_USER_WARNING);
return false;
}
// we could be calling PMA_DBI_connect() to connect to another
// server, for example in the Synchronize feature, so do not
// go back to main login if it fails
if (!$auxiliary_connection) {
PMA_log_user($user, 'mysql-denied');
PMA_auth_fails();
} else {
return false;
}
} else {
PMA_DBI_postConnect($link, $is_controluser);
}
return $link;
}
示例9: __construct
protected final function __construct($config)
{
$this->_db_engine = 'MySQLi';
$this->_db_connect_id = new mysqli($config['dbhost'], $config['dbusername'], $config['dbpassword'], $config['dbdatabase']);
mysqli_options($this->_db_connect_id, MYSQLI_OPT_LOCAL_INFILE, true);
if ($this->_db_connect_id->connect_error) {
trigger_error($this->_db_connect_id->connect_error, E_USER_ERROR);
}
$this->_prefix = $config['dbprefix'];
$this->_setup();
//Run the parent constructor
parent::__construct();
}
示例10: connect
/**
* Connects to a database.
* @return void
* @throws Dibi\Exception
*/
public function connect(array &$config)
{
mysqli_report(MYSQLI_REPORT_OFF);
if (isset($config['resource'])) {
$this->connection = $config['resource'];
} else {
// default values
$config += ['charset' => 'utf8', 'timezone' => date('P'), 'username' => ini_get('mysqli.default_user'), 'password' => ini_get('mysqli.default_pw'), 'socket' => (string) ini_get('mysqli.default_socket'), 'port' => NULL];
if (!isset($config['host'])) {
$host = ini_get('mysqli.default_host');
if ($host) {
$config['host'] = $host;
$config['port'] = ini_get('mysqli.default_port');
} else {
$config['host'] = NULL;
$config['port'] = NULL;
}
}
$foo =& $config['flags'];
$foo =& $config['database'];
$this->connection = mysqli_init();
if (isset($config['options'])) {
if (is_scalar($config['options'])) {
$config['flags'] = $config['options'];
// back compatibility
trigger_error(__CLASS__ . ": configuration item 'options' must be array; for constants MYSQLI_CLIENT_* use 'flags'.", E_USER_NOTICE);
} else {
foreach ((array) $config['options'] as $key => $value) {
mysqli_options($this->connection, $key, $value);
}
}
}
@mysqli_real_connect($this->connection, (empty($config['persistent']) ? '' : 'p:') . $config['host'], $config['username'], $config['password'], $config['database'], $config['port'], $config['socket'], $config['flags']);
// intentionally @
if ($errno = mysqli_connect_errno()) {
throw new Dibi\DriverException(mysqli_connect_error(), $errno);
}
}
if (isset($config['charset'])) {
if (!@mysqli_set_charset($this->connection, $config['charset'])) {
$this->query("SET NAMES '{$config['charset']}'");
}
}
if (isset($config['sqlmode'])) {
$this->query("SET sql_mode='{$config['sqlmode']}'");
}
if (isset($config['timezone'])) {
$this->query("SET time_zone='{$config['timezone']}'");
}
$this->buffered = empty($config['unbuffered']);
}
示例11: Connect
public function Connect()
{
/*$this->link = new MySQLi($this->host, $this->user, $this->pass);
$this->link->select_db($this->dbName);
$this->link->set_charset("utf8");*/
$this->link = mysqli_init();
mysqli_options($this->link, MYSQLI_OPT_LOCAL_INFILE, true);
mysqli_real_connect($this->link, $this->host, $this->user, $this->pass, $this->dbName);
$this->link->select_db($this->dbName);
$this->link->set_charset("utf8");
if (mysqli_connect_errno()) {
return mysqli_connect_error();
} else {
return $this->link;
}
}
示例12: __construct
protected final function __construct($config)
{
$this->_db_engine = 'MySQLi';
$dbport = isset($config['dbport']) && !empty($config['dbport']) ? $config['dbport'] : ini_get('mysqli.default_port');
$dbsocket = isset($config['dbsocket']) && !empty($config['dbsocket']) ? $config['dbsocket'] : ini_get('mysqli.default_socket');
$this->_db_connect_id = new mysqli($config['dbhost'], $config['dbusername'], $config['dbpassword'], $config['dbdatabase'], $dbport, $dbsocket);
mysqli_options($this->_db_connect_id, MYSQLI_OPT_LOCAL_INFILE, true);
if ($this->_db_connect_id->connect_error) {
trigger_error($this->_db_connect_id->connect_error, E_USER_ERROR);
} else {
$this->connected = true;
}
$this->_prefix = $config['dbprefix'];
$this->_setup();
//Run the parent constructor
parent::__construct();
}
示例13: _connect
/**
* Creates connection to database
*
* @return void
*/
protected function _connect()
{
$this->_link = mysqli_init();
if (!$this->_link) {
die('mysqli_init failed.');
}
if (!mysqli_options($this->_link, MYSQLI_OPT_CONNECT_TIMEOUT, 5)) {
die('Setting MYSQLI_OPT_CONNECT_TIMEOUT failed.');
}
mysqli_real_connect($this->_link, INTELLI_DBHOST, INTELLI_DBUSER, INTELLI_DBPASS, INTELLI_DBNAME, INTELLI_DBPORT);
if (!$this->_link) {
$message = !INTELLI_DEBUG ? 'Could not connect.' : 'Could not connect to the database. For more information see error logs.';
die($message);
}
// set active database again
mysqli_select_db($this->_link, INTELLI_DBNAME);
$this->query("SET NAMES 'utf8'");
}
示例14: _connect
protected function _connect()
{
if ($this->_connection) {
return;
}
if (!extension_loaded('mysqli')) {
throw new \Exception('The Mysqli extension is required for this adapter but the extension is not loaded');
}
if (isset($this->_config['port'])) {
$port = (int) $this->_config['port'];
} else {
$port = null;
}
$this->_connection = mysqli_init();
if (!empty($this->_config['driver_options'])) {
foreach ($this->_config['driver_options'] as $option => $value) {
if (is_string($option)) {
// Suppress warnings here
// Ignore it if it's not a valid constant
$option = @constant(strtoupper($option));
if ($option === null) {
continue;
}
}
@mysqli_options($this->_connection, $option, $value);
}
}
// Suppress connection warnings here.
// Throw an exception instead.
try {
$_isConnected = mysqli_real_connect($this->_connection, $this->_config['hostname'], $this->_config['username'], $this->_config['password'], $this->_config['database'], $port);
} catch (Exception $e) {
$_isConnected = false;
}
if ($_isConnected === false || mysqli_connect_errno()) {
$this->closeConnection();
throw new \Exception(mysqli_connect_error());
}
if ($_isConnected && !empty($this->_config['charset'])) {
mysqli_set_charset($this->_connection, $this->_config['charset']);
}
}
示例15: PMA_DBI_connect
function PMA_DBI_connect($user, $password, $is_controluser = FALSE)
{
global $cfg, $php_errormsg;
$server_port = empty($cfg['Server']['port']) ? FALSE : (int) $cfg['Server']['port'];
if (strtolower($cfg['Server']['connect_type']) == 'tcp') {
$cfg['Server']['socket'] = '';
}
// NULL enables connection to the default socket
$server_socket = empty($cfg['Server']['socket']) ? null : $cfg['Server']['socket'];
$link = mysqli_init();
mysqli_options($link, MYSQLI_OPT_LOCAL_INFILE, TRUE);
$client_flags = $cfg['Server']['compress'] && defined('MYSQLI_CLIENT_COMPRESS') ? MYSQLI_CLIENT_COMPRESS : 0;
$return_value = @mysqli_real_connect($link, $cfg['Server']['host'], $user, $password, FALSE, $server_port, $server_socket, $client_flags);
if ($return_value == FALSE) {
PMA_auth_fails();
}
// end if
PMA_DBI_postConnect($link, $is_controluser);
return $link;
}