当前位置: 首页>>代码示例>>PHP>>正文


PHP mysqli::init方法代码示例

本文整理汇总了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);
     }
 }
开发者ID:manelio,项目名称:woolr,代码行数:27,代码来源:rgdb.php

示例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=''");
 }
开发者ID:hazaeluz,项目名称:magento_connect,代码行数:41,代码来源:Mysqli.php

示例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);
         }
     }
 }
开发者ID:Gimle,项目名称:gimle5,代码行数:33,代码来源:mysql.php

示例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;
 }
开发者ID:phossa,项目名称:phossa-db,代码行数:36,代码来源:Driver.php

示例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);
     }
 }
开发者ID:gugglegum,项目名称:demosite,代码行数:10,代码来源:Mysqli.php

示例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());
     }
 }
开发者ID:KristofMols,项目名称:Chrysellia,代码行数:32,代码来源:MySQLiExtension.class.php

示例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');
 }
开发者ID:yu07,项目名称:Pineapple,代码行数:11,代码来源:class.dbconnection.php

示例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;
 }
开发者ID:rharris42,项目名称:Lhp,代码行数:17,代码来源:mysql.php

示例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());
     }
 }
开发者ID:cyberpay,项目名称:multifaucet,代码行数:13,代码来源:db.class.php

示例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());
     }
 }
开发者ID:Auzarius,项目名称:php-inshop-cms,代码行数:14,代码来源:framework.php

示例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;
     }
 }
开发者ID:Strikethegod,项目名称:fanzub,代码行数:18,代码来源:class.mysql.php

示例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());
		}
	}
开发者ID:neslonso,项目名称:sf,代码行数:29,代码来源:MysqliDB.php

示例13: __construct

 public function __construct($host, $user, $passwd, $db, $port, $socket)
 {
     parent::init();
     parent::real_connect($host, $user, $passwd, $db, $port, $socket);
 }
开发者ID:badlamer,项目名称:hhvm,代码行数:5,代码来源:bug33263.php

示例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]);
     }
 }
开发者ID:shen2,项目名称:mdo,代码行数:44,代码来源:Adapter.php

示例15: mysqli

<?php

require_once "connect.inc";
$mysqli = new mysqli();
$mysqli->init();
$mysqli->init();
echo "done";
开发者ID:badlamer,项目名称:hhvm,代码行数:7,代码来源:bug46109.php


注:本文中的mysqli::init方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。