• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP mysqli_init函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中mysqli_init函数的典型用法代码示例。如果您正苦于以下问题:PHP mysqli_init函数的具体用法?PHP mysqli_init怎么用?PHP mysqli_init使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了mysqli_init函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。

示例1: __construct

 private function __construct()
 {
     $this->mysql = mysqli_init();
     $conf = Vera_Conf::getConf('database');
     $this->_connect($conf);
     $this->mysql->set_charset('utf8');
 }
开发者ID:HackathonTsubaki,项目名称:Backend,代码行数:7,代码来源:Database.php


示例2: 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;
}
开发者ID:alex-k,项目名称:velotur,代码行数:49,代码来源:mysqli.dbi.lib.php


示例3: sha_connect

function sha_connect($offset, $host, $db, $port, $socket, $file)
{
    $link = mysqli_init();
    if (!$link->options(MYSQLI_SERVER_PUBLIC_KEY, $file)) {
        printf("[%03d + 001] mysqli_options failed, [%d] %s\n", $offset, $link->errno, $link->error);
        return false;
    }
    if (!$link->real_connect($host, 'shatest', 'shatest', $db, $port, $socket)) {
        printf("[%03d + 002] [%d] %s\n", $offset, $link->connect_errno, $link->connect_error);
        return false;
    }
    if (!($res = $link->query("SELECT id FROM test WHERE id = 1"))) {
        printf("[%03d + 003] [%d] %s\n", $offset, $link->errno, $link->error);
    }
    return false;
    if (!($row = mysqli_fetch_assoc($res))) {
        printf("[%03d + 004] [%d] %s\n", $offset, $link->errno, $link->error);
        return false;
    }
    if ($row['id'] != 1) {
        printf("[%03d + 005] Expecting 1 got %s/'%s'", $offset, gettype($row['id']), $row['id']);
        return false;
    }
    $res->close();
    $link->close();
    return true;
}
开发者ID:badlamer,项目名称:hhvm,代码行数:27,代码来源:mysqli_pam_sha256_public_key_option_invalid.php


示例4: 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;
 }
开发者ID:cedwards-reisys,项目名称:nexus-web,代码行数:43,代码来源:mysqli.php


示例5: db_Connect

function db_Connect($host = CMW_DB_HOST, $login = CMW_DB_LOGIN, $password = CMW_DB_PASSWORD, $name = CMW_DB_NAME, $port = _INI_MYSQLI_DEFAULT_PORT, $socket = _INI_MYSQLI_DEFAULT_SOCKET)
{
    // Safely call this multiple times, only the first time has any effect //
    if (!db_IsConnected()) {
        global $db;
        $db = mysqli_init();
        //mysqli_options($db, ...);
        if (defined('CMW_DB_PORT')) {
            $port = CMW_DB_PORT;
        }
        if (defined('CMW_DB_SOCKET')) {
            $socket = CMW_DB_SOCKET;
        }
        $flags = null;
        // Connect to the database //
        mysqli_real_connect($db, $host, $login, $password, $name, $port, $socket, $flags);
        // http://php.net/manual/en/mysqli.quickstart.connections.php
        if ($db->connect_errno) {
            db_Log("Failed to connect: (" . $db->connect_errno . ") " . $db->connect_error);
        }
        // Set character set to utf8mb4 mode (default is utf8mb3 (utf8). mb4 is required for Emoji)
        mysqli_set_charset($db, 'utf8mb4');
        // More info: http://stackoverflow.com/questions/279170/utf-8-all-the-way-through
    }
}
开发者ID:LastResortGames,项目名称:ludumdare,代码行数:25,代码来源:db_mysql.php


示例6: connect

 /**
  * Установка соединения
  *
  * @return bool
  *
  * @throws \Cms\Db\Engine\Driver\Exception\ConnectionException
  */
 public function connect()
 {
     $resource = null;
     $this->resource = null;
     $this->connected = false;
     $host = $this->host;
     if ($this->isPersistent()) {
         $host = 'p:' . $host;
     }
     try {
         $resource = mysqli_init();
         $resource->set_opt(MYSQLI_OPT_CONNECT_TIMEOUT, $this->timeout);
         $resource->real_connect($host, $this->user, $this->password, $this->database, intval($this->port));
     } catch (\Exception $e) {
         $msg = sprintf('Не удалось установить соединение с базой данных "%s": %s', $this->database, $e->getMessage());
         throw new ConnectionException($msg, $e->getCode());
     }
     if ($resource->connect_errno) {
         $msg = sprintf('Не удалось установить соединение с базой данных "%s": %s', $this->database, $resource->connect_error);
         throw new ConnectionException($msg, $resource->connect_errno);
     }
     $this->resource = $resource;
     $this->connected = true;
     $this->executeConnectQueries();
     return true;
 }
开发者ID:white-bear,项目名称:php-db-layer,代码行数:33,代码来源:MysqliDriver.php


示例7: __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;
             }
         }
     }
 }
开发者ID:dvpablo,项目名称:php-picnic,代码行数:33,代码来源:SimpleMysql.php


示例8: _connect

 protected function _connect()
 {
     //try {
     $this->_config = App::$_registry["db"];
     //pr($this->_config);exit;
     // if connected return
     if ($this->_connection) {
         return;
     }
     if (isset($this->_config['port'])) {
         $port = (int) $this->_config['port'];
     } else {
         $port = null;
     }
     $this->_connection = mysqli_init();
     $_isConnected = @mysqli_real_connect($this->_connection, $this->_config['host'], $this->_config['username'], $this->_config['password'], $this->_config['dbname'], $port, null, MYSQLI_CLIENT_FOUND_ROWS);
     if ($_isConnected === false || mysqli_connect_errno()) {
         $this->closeConnection();
         //throw new \Exception(mysqli_connect_error());
         show_error('DB Error', mysqli_connect_error());
     }
     //}
     /* catch (\Exception $e) {
     			echo $e->getTraceAsString();
     		} */
 }
开发者ID:Kishanrajdev047,项目名称:Rest-api,代码行数:26,代码来源:Dbconfig.php


示例9: __construct

 public function __construct($dsn)
 {
     $base = preg_replace('{^/}s', '', $dsn['path']);
     if (!class_exists('mysqli')) {
         return $this->_setLastError('-1', 'mysqli extension is not loaded', 'mysqli');
     }
     try {
         $this->link = mysqli_init();
         if (!$this->link) {
             $this->_setLastError(-1, 'mysqli_init failed', 'new mysqli');
         } else {
             if (!$this->link->options(MYSQLI_OPT_CONNECT_TIMEOUT, isset($dsn['timeout']) && $dsn['timeout'] ? $dsn['timeout'] : 0)) {
                 $this->_setLastError($this->link->connect_errno, $this->link->connect_error, 'new mysqli');
             } else {
                 if (!$this->link->real_connect(isset($dsn['persist']) && $dsn['persist'] ? 'p:' . $dsn['host'] : $dsn['host'], $dsn['user'], isset($dsn['pass']) ? $dsn['pass'] : '', $base, empty($dsn['port']) ? NULL : $dsn['port'], NULL, isset($dsn['compression']) && $dsn['compression'] ? MYSQLI_CLIENT_COMPRESS : NULL)) {
                     $this->_setLastError($this->link->connect_errno, $this->link->connect_error, 'new mysqli');
                 } else {
                     if (!$this->link->set_charset(isset($dsn['enc']) ? $dsn['enc'] : 'UTF8')) {
                         $this->_setLastError($this->link->connect_errno, $this->link->connect_error, 'new mysqli');
                     } else {
                         $this->isMySQLnd = method_exists('mysqli_result', 'fetch_all');
                     }
                 }
             }
         }
         $this->isMySQLnd = method_exists('mysqli_result', 'fetch_all');
     } catch (mysqli_sql_exception $e) {
         $this->_setLastError($e->getCode(), $e->getMessage(), 'new mysqli');
     }
 }
开发者ID:AntiqS,项目名称:altocms,代码行数:30,代码来源:Mysqli.php


示例10: connect

 /**
  * Connect to the database
  * 
  * @return bool false on failure / mysqli MySQLi object instance on success
  */
 public function connect()
 {
     // Try and connect to the database
     // if (!isset(self::$connection)) {
     // Load configuration as an array. Use the actual location of your configuration file
     //    self::$connection = new mysqli('localhost', 'root', 'root', 'servicioslegales');
     //  }
     self::$connection = mysqli_init();
     if (!self::$connection) {
         die('mysqli_init failed');
     }
     if (!self::$connection->options(MYSQLI_INIT_COMMAND, 'SET AUTOCOMMIT = 0')) {
         die('Setting MYSQLI_INIT_COMMAND failed');
     }
     if (!self::$connection->options(MYSQLI_OPT_CONNECT_TIMEOUT, 5)) {
         die('Setting MYSQLI_OPT_CONNECT_TIMEOUT failed');
     }
     if (!self::$connection->real_connect('localhost', 'root', 'root', 'servicioslegales')) {
         die('Connect Error (' . mysqli_connect_errno() . ') ' . mysqli_connect_error());
     }
     // If connection was not successful, handle the error
     if (self::$connection === false) {
         // Handle error - notify administrator, log to a file, show an error screen, etc.
         return false;
     }
     return self::$connection;
 }
开发者ID:JeysonMontenegro,项目名称:ProyectoBases2,代码行数:32,代码来源:Conexion2.php


示例11: 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);
 }
开发者ID:myqee,项目名称:database-mysqli,代码行数:35,代码来源:Driver.php


示例12: __construct

 protected function __construct()
 {
     $this->mysqli = mysqli_init();
     if (!$this->mysqli->real_connect(Configuration::read('db_host'), Configuration::read('db_username'), Configuration::read('db_password'), Configuration::read('db_name'))) {
         throw new MysqliConnectionException('Connect Error (' . mysqli_connect_errno() . ') ' . mysqli_connect_error());
     }
 }
开发者ID:rhokburlington,项目名称:species-invaders,代码行数:7,代码来源:DB.php


示例13: connect

 /**
  * Database connection
  *
  * @param array $conf
  * @return bool|resource
  */
 private function connect()
 {
     if ($this->driver == 'ext/mysqli') {
         $link = mysqli_init();
         if (!$link) {
             $link = false;
         } else {
             $link = @mysqli_connect($this->host, $this->user, $this->password);
             if ($link !== false) {
                 $db = @mysqli_select_db($link, $this->db);
                 mysqli_set_charset($link, "utf8");
             }
         }
         if ($link === false) {
             $this->error('MySQL connection error: ' . mysqli_connect_error());
         }
     } else {
         $link = @mysql_connect($this->host, $this->user, $this->password);
         if ($link !== false) {
             $db = @mysql_select_db($this->db, $link);
             mysql_query("SET NAMES 'utf8'");
         } else {
             if ($link === false) {
                 $this->error('MySQL connection error: ' . mysql_error());
             }
         }
     }
     return $link;
 }
开发者ID:prochor666,项目名称:lethe,代码行数:35,代码来源:Mysqldb.php


示例14: connect

 /**
  * Connect to a database and log in as the specified user.
  *
  * @param string $dsn the data source name (see DB::parseDSN for syntax)
  * @param boolean $persistent (optional) whether the connection should
  *                            be persistent
  * @return mixed DB_OK on success, a DB error on failure
  * @access public
  */
 function connect($dsninfo, $persistent = false)
 {
     if (!DB::assertExtension('mysqli')) {
         return $this->raiseError(DB_ERROR_EXTENSION_NOT_FOUND);
     }
     $this->dsn = $dsninfo;
     $conn = false;
     @ini_set('track_errors', true);
     if ($this->getOption('ssl') === true) {
         $init = mysqli_init();
         mysqli_ssl_set($init, empty($dsninfo['key']) ? null : $dsninfo['key'], empty($dsninfo['cert']) ? null : $dsninfo['cert'], empty($dsninfo['ca']) ? null : $dsninfo['ca'], empty($dsninfo['capath']) ? null : $dsninfo['capath'], empty($dsninfo['cipher']) ? null : $dsninfo['cipher']);
         if ($conn = @mysqli_real_connect($init, $dsninfo['hostspec'], $dsninfo['username'], $dsninfo['password'], $dsninfo['database'], $dsninfo['port'], $dsninfo['socket'])) {
             $conn = $init;
         }
     } else {
         $conn = @mysqli_connect($dsninfo['hostspec'], $dsninfo['username'], $dsninfo['password'], $dsninfo['database'], $dsninfo['port'], $dsninfo['socket']);
     }
     @ini_restore('track_errors');
     if (!$conn) {
         if (($err = @mysqli_connect_error()) != '') {
             return $this->raiseError(DB_ERROR_CONNECT_FAILED, null, null, null, $err);
         } elseif (empty($php_errormsg)) {
             return $this->raiseError(DB_ERROR_CONNECT_FAILED);
         } else {
             return $this->raiseError(DB_ERROR_CONNECT_FAILED, null, null, null, $php_errormsg);
         }
     }
     if ($dsninfo['database']) {
         $this->_db = $dsninfo['database'];
     }
     $this->connection = $conn;
     return DB_OK;
 }
开发者ID:BackupTheBerlios,项目名称:hem,代码行数:42,代码来源:mysqli.php


示例15: open

 /**
  * Opens the database connection.
  *
  * @return bool Boolean true on success, throws a RuntimeException otherwise
  */
 public function open()
 {
     if (is_object($this->link)) {
         return true;
     }
     if ($this->ssl == true) {
         if (empty($this->clientcert)) {
             throw new \RuntimeException("clientcert not defined");
         }
         if (empty($this->clientkey)) {
             throw new \RuntimeException("clientkey not defined");
         }
         if (empty($this->cacert)) {
             throw new \RuntimeException("cacert not defined");
         }
         $this->link = mysqli_init();
         $this->link->options(MYSQLI_OPT_SSL_VERIFY_SERVER_CERT, true);
         $this->link->ssl_set($this->clientkey, $this->clientcert, $this->cacert, NULL, NULL);
         $this->link->real_connect($this->host, $this->username, $this->password, $this->database, $this->port, $this->socket, MYSQLI_CLIENT_SSL);
     } else {
         $this->link = mysqli_connect($this->host, $this->username, $this->password, $this->database, $this->port, $this->socket);
     }
     if (mysqli_connect_errno()) {
         throw new \RuntimeException(sprintf('could not connect to %s : (%d) %s', $this->database, mysqli_connect_errno(), mysqli_connect_error()));
     }
     if (!mysqli_set_charset($this->link, $this->charset)) {
         throw new \RuntimeException(sprintf('error loading character set %s : (%d) %s', $this->charset, mysqli_errno($this->link), mysqli_error($this->link)));
     }
     return true;
 }
开发者ID:nramenta,项目名称:dabble,代码行数:35,代码来源:Database.php


示例16: __construct

 public final function __construct($Server, $Username, $Password, $Name, $Timeout = 30)
 {
     $this->DB_server = $Server;
     $this->DB_user = $Username;
     $this->DB_passwd = $Password;
     $this->DB_name = $Name;
     $this->DB_timeout = $Timeout;
     $this->mySQLi = mysqli_init();
     if (!$this->mySQLi) {
         die($this->mySQLi->error);
     } else {
         if ($this->DB_timeout != 0) {
             $this->mySQLi->options(MYSQLI_OPT_CONNECT_TIMEOUT, $this->DB_timeout);
         }
     }
     if ($this->connect()) {
         $this->connected = true;
     } else {
         $this->connected = false;
         if (DEBUG_MODE) {
             die($this->mySQLi->error);
         }
     }
     if ($this->selectDB()) {
         $this->connected = true;
         return true;
     } else {
         $this->connected = false;
         if (DEBUG_MODE) {
             die($this->mySQLi->error);
         }
         return false;
     }
 }
开发者ID:yielruse,项目名称:Making-Isometric-Real-time-Games,代码行数:34,代码来源:class.dbutil.php


示例17: connect

 public function connect()
 {
     if ($this->_connection) {
         return;
     }
     if (static::$_set_names === null) {
         // Determine if we can use mysqli_set_charset(), which is only
         // available on PHP 5.2.3+ when compiled against MySQL 5.0+
         static::$_set_names = !function_exists('mysqli_set_charset');
     }
     // Extract the connection parameters, adding required variables
     extract($this->_config['connection'] + array('database' => '', 'hostname' => '', 'port' => '', 'socket' => '', 'username' => '', 'password' => '', 'persistent' => false, 'compress' => true));
     // Prevent this information from showing up in traces
     unset($this->_config['connection']['username'], $this->_config['connection']['password']);
     try {
         if ($socket != '') {
             $port = null;
         } elseif ($port != '') {
             $socket = null;
         } else {
             $socket = null;
             $port = null;
         }
         if ($persistent) {
             // Create a persistent connection
             if ($compress) {
                 $mysqli = mysqli_init();
                 $mysqli->real_connect('p:' . $hostname, $username, $password, $database, $port, $socket, MYSQLI_CLIENT_COMPRESS);
                 $this->_connection = $mysqli;
             } else {
                 $this->_connection = new \MySQLi('p:' . $hostname, $username, $password, $database, $port, $socket);
             }
         } else {
             // Create a connection and force it to be a new link
             if ($compress) {
                 $mysqli = mysqli_init();
                 $mysqli->real_connect($hostname, $username, $password, $database, $port, $socket, MYSQLI_CLIENT_COMPRESS);
                 $this->_connection = $mysqli;
             } else {
                 $this->_connection = new \MySQLi($hostname, $username, $password, $database, $port, $socket);
             }
         }
         if ($this->_connection->error) {
             // Unable to connect, select database, etc
             throw new \Database_Exception($this->_connection->error, $this->_connection->errno);
         }
     } catch (\ErrorException $e) {
         // No connection exists
         $this->_connection = null;
         throw new \Database_Exception('No MySQLi Connection<br>\\n' . $e->getMessage() . "<br>\n" . "hostname:" . $hostname . "<br>\n" . "username:" . $username . "<br>\n" . "password:" . $password . "<br>\n" . "database:" . $database . "<br>\n" . "port:" . $port . "<br>\n", 0);
         throw new \Database_Exception('No MySQLi Connection', 0);
     }
     // \xFF is a better delimiter, but the PHP driver uses underscore
     $this->_connection_id = sha1($hostname . '_' . $username . '_' . $password);
     if (!empty($this->_config['charset'])) {
         // Set the character set
         $this->set_charset($this->_config['charset']);
     }
     static::$_current_databases[$this->_connection_id] = $database;
 }
开发者ID:OkadaMitsuo,项目名称:pointcast_server,代码行数:60,代码来源:connection.php


示例18: __construct

 public function __construct($dbName, $dbHost, $dbUser, $dbPassword, $Port, $Socket, $dbFlags, $NoUTF8)
 {
     $this->dbObject = mysqli_init();
     if ($this->dbObject === FALSE) {
         $this->TriggerSQLError("Could not initialize MySQLi object for [{$dbName}]");
     }
     $this->dbObject->options(MYSQLI_OPT_LOCAL_INFILE, true);
     if (is_null($dbFlags)) {
         $connect = $this->dbObject->real_connect($dbHost, $dbUser, $dbPassword, $dbName, $Port, $Socket, MYSQLI_CLIENT_FOUND_ROWS);
     } else {
         $connect = $this->dbObject->real_connect($dbHost, $dbUser, $dbPassword, $dbName, $Port, $Socket, $dbFlags);
     }
     if ($connect === FALSE) {
         $this->TriggerSQLError("Error connecting to database {$dbName}, error number [{$this->dbObject->connect_errno}] message {$this->dbObject->connect_error}");
     }
     $this->dbObject->real_query("set net_write_timeout=1200");
     $Version = phpversion();
     $VerInfo = explode(".", $Version);
     if ($NoUTF8 === FALSE && ($VerInfo[0] > 5 || $VerInfo[0] == 5 && $VerInfo[1] >= 3)) {
         $this->dbObject->set_charset("utf8");
     }
     $this->DatabaseName = $dbName;
     $this->UserName = $dbUser;
     $this->Pwd = $dbPassword;
     $this->HostName = $dbHost;
 }
开发者ID:programermaster,项目名称:pall_extr,代码行数:26,代码来源:Database.php


示例19: connect

 public function connect()
 {
     require_once "connect.inc";
     $link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket);
     var_dump($link);
     $link = mysqli_init();
     /* @ is to suppress 'Property access is not allowed yet' */
     @var_dump($link);
     $mysql = new my_mysqli($host, $user, $passwd, $db, $port, $socket);
     $mysql->query("DROP TABLE IF EXISTS test_bug34810_table_1");
     $mysql->query("CREATE TABLE test_bug34810_table_1 (a int not null)");
     $mysql->query("SET sql_mode=''");
     $mysql->query("INSERT INTO test_bug34810_table_1 VALUES (1),(2),(NULL)");
     $warning = $mysql->get_warnings();
     if (!$warning) {
         printf("[001] No warning!\n");
     }
     if ($warning->errno == 1048 || $warning->errno == 1253) {
         /* 1048 - Column 'a' cannot be null, 1263 - Data truncated; NULL supplied to NOT NULL column 'a' at row */
         if ("HY000" != $warning->sqlstate) {
             printf("[003] Wrong sql state code: %s\n", $warning->sqlstate);
         }
         if ("" == $warning->message) {
             printf("[004] Message string must not be empty\n");
         }
     } else {
         printf("[002] Empty error message!\n");
         var_dump($warning);
     }
 }
开发者ID:badlamer,项目名称:hhvm,代码行数:30,代码来源:bug34810.php


示例20: connect

 /** Connect to a mysql database using mysqli.
  *
  * @param array $db_config Connection information.
  */
 public function connect($db_host = null, $db_user = null, $db_pass = null, $db = null)
 {
     $this->db_config = array('db_host' => $db_host, 'db_user' => $db_user, 'db_pass' => $db_pass, 'db' => $db);
     $this->mysqli = mysqli_init();
     $this->mysqli->real_connect($db_host, $db_user, $db_pass, $db);
     $this->mysqli->set_charset("utf8");
 }
开发者ID:nekudo,项目名称:decaptcha,代码行数:11,代码来源:class.db_handling.php



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP mysqli_insert_id函数代码示例发布时间:2022-05-15
下一篇:
PHP mysqli_info函数代码示例发布时间:2022-05-15
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap