本文整理汇总了PHP中mysqli::init方法的典型用法代码示例。如果您正苦于以下问题:PHP mysqli::init方法的具体用法?PHP mysqli::init怎么用?PHP mysqli::init使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mysqli
的用法示例。
在下文中一共展示了mysqli::init方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: connect
function connect()
{
if ($this->connected) {
return;
}
parent::init();
parent::options(MYSQLI_OPT_CONNECT_TIMEOUT, $this->connect_timeout);
if ($this->persistent && version_compare(PHP_VERSION, '5.3.0') > 0) {
$this->connected = parent::real_connect('p:' . $this->dbhost, $this->dbuser, $this->dbpassword, $this->dbname, $this->port);
} else {
$this->connected = parent::real_connect($this->dbhost, $this->dbuser, $this->dbpassword, $this->dbname, $this->port);
}
if (!$this->connected) {
header('HTTP/1.1 503 Service Unavailable');
die;
}
$this->set_charset('utf8');
if (!$this->ban_checked) {
// Check the IP is not banned before doing anything more
check_ip_noaccess(2);
// 2 == don't check in cache
$this->ban_checked = true;
}
if ($this->initial_query) {
$this->query($this->initial_query);
}
}
示例2: _connect
/**
* Creates a real connection to the database with multi-query capability.
*
* @return void
* @throws Zend_Db_Adapter_Mysqli_Exception
*/
protected function _connect()
{
if ($this->_connection) {
return;
}
if (!extension_loaded('mysqli')) {
throw new Zend_Db_Adapter_Exception('mysqli extension is not installed');
}
// Suppress connection warnings here.
// Throw an exception instead.
@($conn = new mysqli());
if (false === $conn || mysqli_connect_errno()) {
throw new Zend_Db_Adapter_Mysqli_Exception(mysqli_connect_errno());
}
$conn->init();
$conn->options(MYSQLI_OPT_LOCAL_INFILE, true);
#$conn->options(MYSQLI_CLIENT_MULTI_QUERIES, true);
$port = !empty($this->_config['port']) ? $this->_config['port'] : null;
$socket = !empty($this->_config['unix_socket']) ? $this->_config['unix_socket'] : null;
// socket specified in host config
if (strpos($this->_config['host'], '/') !== false) {
$socket = $this->_config['host'];
$this->_config['host'] = null;
} elseif (strpos($this->_config['host'], ':') !== false) {
list($this->_config['host'], $port) = explode(':', $this->_config['host']);
}
#echo "<pre>".print_r($this->_config,1)."</pre>"; die;
@$conn->real_connect($this->_config['host'], $this->_config['username'], $this->_config['password'], $this->_config['dbname'], $port, $socket);
if (mysqli_connect_errno()) {
throw new Zend_Db_Adapter_Mysqli_Exception(mysqli_connect_error());
}
$this->_connection = $conn;
/** @link http://bugs.mysql.com/bug.php?id=18551 */
$this->_connection->query("SET SQL_MODE=''");
}
示例3: __construct
/**
* Create a new Mysqli object.
*
* @param array $params
* @return object
*/
public function __construct($key)
{
mysqli_report(MYSQLI_REPORT_STRICT);
$params = Config::get('mysql.' . $key);
if ($params === null && IS_SUBSITE) {
$params = MainConfig::get('mysql.' . $key);
}
if ($params === null) {
$params = [];
}
parent::init();
$params['pass'] = isset($params['pass']) ? $params['pass'] : '';
$params['user'] = isset($params['user']) ? $params['user'] : 'root';
$params['host'] = isset($params['host']) ? $params['host'] : '127.0.0.1';
$params['port'] = isset($params['port']) ? $params['port'] : 3306;
$params['timeout'] = isset($params['timeout']) ? $params['timeout'] : 30;
$params['charset'] = isset($params['charset']) ? $params['charset'] : 'utf8';
$params['database'] = isset($params['database']) ? $params['database'] : false;
parent::options(MYSQLI_OPT_CONNECT_TIMEOUT, $params['timeout']);
parent::real_connect($params['host'], $params['user'], $params['pass'], $params['database'], $params['port']);
if ($this->errno === 0) {
$this->set_charset($params['charset']);
if (isset($params['cache']) && $params['cache'] === false) {
$this->cache(false);
}
}
}
示例4: realConnect
/**
* {@inheritDoc}
*/
protected function realConnect(array $parameters)
{
// init
$this->link = new \mysqli();
$this->link->init();
// set driver specific options
if (!empty($parameters['options'])) {
foreach ($parameters['options'] as $option => $value) {
$option = strtoupper($option);
$this->attributes[$option] = $value;
}
}
foreach ($this->attributes as $attr => $value) {
if (is_string($attr)) {
$option = constant($attr);
if (defined($option)) {
$this->link->options($option, $value);
}
} else {
$this->link->options($attr, $value);
}
}
// real connect
$this->link->real_connect(isset($parameters['host']) ? $parameters['host'] : 'localhost', isset($parameters['username']) ? $parameters['username'] : 'root', isset($parameters['password']) ? $parameters['password'] : null, isset($parameters['db']) ? $parameters['db'] : null, isset($parameters['port']) ? (int) $parameters['port'] : null, isset($parameters['socket']) ? $parameters['socket'] : null);
if ($this->link->connect_error) {
throw new LogicException(Message::get(Message::DB_CONNECT_FAIL, $this->link->connect_errno, $this->link->connect_error), Message::DB_CONNECT_FAIL);
}
// set charset
if (!empty($parameters['charset'])) {
$this->link->set_charset($parameters['charset']);
}
return $this;
}
示例5: __construct
public function __construct($host, $user, $pass, $db)
{
parent::init();
if (!parent::real_connect($host, $user, $pass, $db)) {
throw new Exception('Ошибка подключения (' . mysqli_connect_errno() . ') ' . mysqli_connect_error());
}
if (!$this->set_charset('utf8')) {
throw new Exception('Ошибка при загрузке набора символов utf8: ' . $this->error);
}
}
示例6: __construct
/**
* Constructor for the MySQLi Extension
*
* Throws an exception when connection fails
*
* @param $Host
* The hostname/ip address of the database server
*
* @param $Port
* The port on which the database server is listening
*
* @param $UserName
* A UserName which has access to the database we'll be using.
*
* @param $Password
* The Password for the UserName provided
*
* @param $Database
* The Database which contains the Neflaria tables
*
* @throws Exception
*/
public function __construct($Host, $UserName, $Password, $Database, $Port)
{
parent::init();
if (!parent::options(MYSQLI_OPT_CONNECT_TIMEOUT, 5)) {
$this->LogError('?', 'Setting the connect timeout failed');
}
if (!parent::real_connect($Host, $UserName, $Password, $Database, $Port)) {
$this->LogError(mysqli_connect_errno(), mysqli_connect_error());
}
}
示例7: __construct
public function __construct($host = '127.0.0.1', $username = 'root', $password = 'root', $dbname = 'web_train')
{
parent::init();
if (!parent::options(MYSQLI_OPT_CONNECT_TIMEOUT, 5)) {
die('Setting options failed');
}
if (!parent::real_connect($host, $username, $password, $dbname)) {
die('Connect to db failed');
}
parent::query('set names utf8');
}
示例8: connect
/**
* connect - Connects to mysql server
*
* @throws exception
*/
public function connect()
{
if (!$this->connected) {
parent::init();
if (!parent::real_connect($this->host, $this->user, $this->pass, $this->db, $this->port)) {
throw new Exception($this->connect_error);
} else {
$this->connected = true;
}
}
return $this;
}
示例9: __construct
private final function __construct()
{
parent::init();
if (!parent::options(MYSQLI_INIT_COMMAND, 'SET AUTOCOMMIT = 0')) {
throw new Exception('Setting MYSQLI_INIT_COMMAND failed');
}
if (!parent::options(MYSQLI_OPT_CONNECT_TIMEOUT, 5)) {
throw new Exception('Setting MYSQLI_OPT_CONNECT_TIMEOUT failed');
}
if (!parent::real_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME)) {
throw new Exception('Connect Error (' . mysqli_connect_errno() . ') ' . mysqli_connect_error());
}
}
示例10: rcon
public function rcon($host, $user, $pass, $db)
{
parent::init();
if (!parent::options(MYSQLI_INIT_COMMAND, 'SET AUTOCOMMIT = 0')) {
die('Setting MYSQLI_INIT_COMMAND failed');
}
if (!parent::options(MYSQLI_OPT_CONNECT_TIMEOUT, 5)) {
die('Setting MYSQLI_OPT_CONNECT_TIMEOUT failed');
}
#$db_connection = new mysqli('localhost', 'root', '', 'brechbuhler');
if (!parent::real_connect($host, $user, $pass, $db)) {
die('Connect Error (' . mysqli_connect_errno() . ') ' . mysqli_connect_error());
}
}
示例11: __construct
public function __construct($server = 'localhost', $database = '', $username = '', $password = '', $port = '')
{
parent::init();
$this->connect['server'] = $server;
$this->connect['database'] = $database;
$this->connect['schema'] = $database;
// MySQL doesn't support schema's
$this->connect['username'] = $username;
$this->connect['password'] = $password;
$this->connect['port'] = empty($port) ? ini_get('mysqli.default_port') : $port;
$this->connect['persistent'] = true;
if (!isset(self::$stats['count'])) {
self::$stats['count'] = 0;
}
if (!isset(self::$stats['duration'])) {
self::$stats['duration'] = (double) 0;
}
}
示例12: __construct
/**
* Constructor: Conecta a MySQL y establece el charset a utf8
* @param string $host host de MySQL
* @param string $user usuario de acceso a MySQL
* @param string $pass contraseña del usuario de acceso a MySQL
* @param string $db nombbre de esquema de MySQL
* @throws DBException si no puede conectar o establecer el charset a utf8
*/
public function __construct($host, $user, $pass, $db) {
parent::init();
/*
if (!parent::options(MYSQLI_INIT_COMMAND, 'SET AUTOCOMMIT = 0')) {
throw new exception('Setting MYSQLI_INIT_COMMAND failed');
}
if (!parent::options(MYSQLI_OPT_CONNECT_TIMEOUT, 5)) {
throw new exception('Setting MYSQLI_OPT_CONNECT_TIMEOUT failed');
}
*/
if (!parent::real_connect($host, $user, $pass, $db)) {
//throw new exception($this->connect_error, $this->connect_errno);
//$connect_error falla hasta PHP 5.3.0, asi que usamos la siguiente
throw new DBException(mysqli_connect_error(), mysqli_connect_errno());
}
/* change character set to utf8 */
if (!parent::set_charset("utf8")) {
throw new DBException(mysqli_connect_error(), mysqli_connect_errno());
}
}
示例13: __construct
public function __construct($host, $user, $passwd, $db, $port, $socket)
{
parent::init();
parent::real_connect($host, $user, $passwd, $db, $port, $socket);
}
示例14: __construct
/**
* Constructor.
*
* $config is an array of key/value pairs
* containing configuration options. These options are common to most adapters:
*
* dbname => (string) The name of the database to user
* username => (string) Connect to the database as this username.
* password => (string) Password associated with the username.
* host => (string) What host to connect to, defaults to localhost
*
* Some options are used on a case-by-case basis by adapters:
*
* port => (string) The port of the database
* persistent => (boolean) Whether to use a persistent connection or not, defaults to false
* protocol => (string) The network protocol, defaults to TCPIP
* caseFolding => (int) style of case-alteration used for identifiers
*
* @param array $config An array having configuration data
* @throws Zend_Db_Adapter_Exception
*/
public function __construct($config)
{
parent::init();
$this->_config = array_merge($this->_config, $config);
$this->_config['driver_options'] = isset($config['driver_options']) ? $config['driver_options'] : array();
if (!empty($this->_config['options'])) {
// obtain quoting property if there is one
if (array_key_exists(self::AUTO_QUOTE_IDENTIFIERS, $this->_config['options'])) {
$this->_autoQuoteIdentifiers = (bool) $this->_config['options'][self::AUTO_QUOTE_IDENTIFIERS];
}
// obtain auto reconnect on unserialize property if there is one
if (array_key_exists(self::AUTO_RECONNECT_ON_UNSERIALIZE, $this->_config['options'])) {
$this->_autoReconnectOnUnserialize = (bool) $this->_config['options'][self::AUTO_RECONNECT_ON_UNSERIALIZE];
}
}
// 修改了原来的Zend_Db代码,在不开启profiler的情况下,不再生成profiler实例
if (array_key_exists(self::PROFILER, $this->_config)) {
if ($this->_config[self::PROFILER]) {
$this->setProfiler($this->_config[self::PROFILER]);
}
unset($this->_config[self::PROFILER]);
}
}
示例15: mysqli
<?php
require_once "connect.inc";
$mysqli = new mysqli();
$mysqli->init();
$mysqli->init();
echo "done";