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


PHP mysqli_real_connect函数代码示例

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


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

示例1: Open

 /**
  * 连接数据库
  * @param array $array 数据库连接配置
  *              $array=array(
  *                  'dbmysql_server',
  *                  'dbmysql_username',
  *                  'dbmysql_password',
  *                  'dbmysql_name',
  *                  'dbmysql_pre',
  *                  'dbmysql_port',
  *                  'persistent'
  *                  'engine')
  * @return bool
  */
 public function Open($array)
 {
     $db = mysqli_init();
     if ($array[6] == true) {
         $array[0] = 'p:' . $array[0];
     }
     //mysqli_options($db,MYSQLI_READ_DEFAULT_GROUP,"max_allowed_packet=50M");
     if (@mysqli_real_connect($db, $array[0], $array[1], $array[2], $array[3], $array[5])) {
         $myver = mysqli_get_server_info($db);
         $this->version = substr($myver, 0, strpos($myver, "-"));
         if (version_compare($this->version, '5.5.3') >= 0) {
             $u = "utf8mb4";
         } else {
             $u = "utf8";
         }
         if (mysqli_set_charset($db, $u) == false) {
             mysqli_set_charset($db, "utf8");
         }
         $this->db = $db;
         $this->dbname = $array[3];
         $this->dbpre = $array[4];
         $this->dbengine = $array[7];
         return true;
     }
     return false;
 }
开发者ID:zblogcn,项目名称:zblogphp,代码行数:40,代码来源:dbmysqli.php

示例2: _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

示例3: 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) {
        if ($is_controluser) {
            trigger_error($GLOBALS['strControluserFailed'], E_USER_WARNING);
            return false;
        }
        PMA_auth_fails();
    }
    // end if
    PMA_DBI_postConnect($link, $is_controluser);
    return $link;
}
开发者ID:gerrywastaken,项目名称:phpmyadmin-GitHubed,代码行数:53,代码来源:mysqli.dbi.lib.php

示例4: __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

示例5: _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;
     }
 }
开发者ID:ar-mohammadi,项目名称:cwr_cwrdiversity.org,代码行数:35,代码来源:adodb-mysqli.inc.php

示例6: 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

示例7: _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;
     }
     // Set connection options
     // Not implemented now
     // mysqli_options($this->_connection,,);
     if (mysqli_real_connect($this->_connectionID, $argHostname, $argUsername, $argPassword, $argDatabasename, $this->port, $this->socket, $this->clientFlags)) {
         if ($argDatabasename) {
             return $this->SelectDB($argDatabasename);
         }
         return true;
     } else {
         if ($this->debug) {
             ADOConnection::outp("Could't connect : " . $this->ErrorMsg());
         }
         return false;
     }
 }
开发者ID:noikiy,项目名称:owaspbwa,代码行数:28,代码来源:adodb-mysqli.inc.php

示例8: 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

示例9: 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

示例10: _connect

 /**
  * Create connection with Db
  */
 private function _connect()
 {
     $this->_connection = mysqli_init();
     $_isConnected = @mysqli_real_connect($this->_connection, DB_SERVER, DB_USERNAME, DB_PASSWORD, DB_NAME, DB_PORT, null, MYSQLI_CLIENT_FOUND_ROWS);
     if ($_isConnected === false || mysqli_connect_errno()) {
         $this->closeConnection();
     }
 }
开发者ID:mayurtakawale88,项目名称:store,代码行数:11,代码来源:Db.php

示例11: 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;
     }
 }
开发者ID:yfix,项目名称:yf,代码行数:59,代码来源:yf_db_driver_mysqli.class.php

示例12: connect

 public function connect()
 {
     if ($this->isConnected()) {
         return true;
     }
     @mysqli_real_connect($this->link, $this->route['host'], $this->route['username'], $this->route['password'], $this->route['dbname'], $this->route['port'], $this->route['socket']);
     $this->throwErrors();
     $this->connected = true;
 }
开发者ID:seansitter,项目名称:picnicphp,代码行数:9,代码来源:Mysqli.php

示例13: connect

 public static function connect()
 {
     MySQLConnection::$db_connection = mysqli_init();
     $connected = @mysqli_real_connect(MySQLConnection::$db_connection, MySQLConfiguration::host, MySQLConfiguration::username, MySQLConfiguration::password, MySQLConfiguration::database, MySQLConfiguration::port, MySQLConfiguration::socket, MYSQLI_CLIENT_COMPRESS);
     if (!$connected) {
         //Output error details
         Error::halt(503, 'service unavailable', 'Temporarily unable to process request. Failed to establish a connection with MySQL. Please retry.');
     }
 }
开发者ID:tsing,项目名称:commando,代码行数:9,代码来源:MySQLConnection.php

示例14: sql_connect

 /**
  * {@inheritDoc}
  */
 function sql_connect($sqlserver, $sqluser, $sqlpassword, $database, $port = false, $persistency = false, $new_link = false)
 {
     if (!function_exists('mysqli_connect')) {
         $this->connect_error = 'mysqli_connect function does not exist, is mysqli extension installed?';
         return $this->sql_error('');
     }
     // Mysqli extension supports persistent connection since PHP 5.3.0
     $this->persistency = version_compare(PHP_VERSION, '5.3.0', '>=') ? $persistency : false;
     $this->user = $sqluser;
     // If persistent connection, set dbhost to localhost when empty and prepend it with 'p:' prefix
     $this->server = $this->persistency ? 'p:' . ($sqlserver ? $sqlserver : 'localhost') : $sqlserver;
     $this->dbname = $database;
     $port = !$port ? null : $port;
     // If port is set and it is not numeric, most likely mysqli socket is set.
     // Try to map it to the $socket parameter.
     $socket = null;
     if ($port) {
         if (is_numeric($port)) {
             $port = (int) $port;
         } else {
             $socket = $port;
             $port = null;
         }
     }
     $this->db_connect_id = mysqli_init();
     if (!@mysqli_real_connect($this->db_connect_id, $this->server, $this->user, $sqlpassword, $this->dbname, $port, $socket, MYSQLI_CLIENT_FOUND_ROWS)) {
         $this->db_connect_id = '';
     }
     if ($this->db_connect_id && $this->dbname != '') {
         @mysqli_query($this->db_connect_id, "SET NAMES 'utf8'");
         // enforce strict mode on databases that support it
         if (version_compare($this->sql_server_info(true), '5.0.2', '>=')) {
             $result = @mysqli_query($this->db_connect_id, 'SELECT @@session.sql_mode AS sql_mode');
             if ($result !== null) {
                 $row = @mysqli_fetch_assoc($result);
                 $modes = array_map('trim', explode(',', $row['sql_mode']));
             } else {
                 $modes = array();
             }
             @mysqli_free_result($result);
             // TRADITIONAL includes STRICT_ALL_TABLES and STRICT_TRANS_TABLES
             if (!in_array('TRADITIONAL', $modes)) {
                 if (!in_array('STRICT_ALL_TABLES', $modes)) {
                     $modes[] = 'STRICT_ALL_TABLES';
                 }
                 if (!in_array('STRICT_TRANS_TABLES', $modes)) {
                     $modes[] = 'STRICT_TRANS_TABLES';
                 }
             }
             $mode = implode(',', $modes);
             @mysqli_query($this->db_connect_id, "SET SESSION sql_mode='{$mode}'");
         }
         return $this->db_connect_id;
     }
     return $this->sql_error('');
 }
开发者ID:mike-a-b,项目名称:crossfit,代码行数:59,代码来源:mysqli.php

示例15: createConnection

 private function createConnection($conf)
 {
     $handle = mysqli_init();
     $ret = mysqli_real_connect($handle, $conf['ip'], $conf['user'], $conf['pass'], $this->dbname, $conf['port']);
     if (!$ret) {
         mysqli_close($handle);
         throw new \Exception('db.ConnectError ' . mysqli_error($handle));
     }
     mysqli_set_charset($handle, $conf['charset']);
     return $handle;
 }
开发者ID:comdeng,项目名称:firegit,代码行数:11,代码来源:MysqlDb.php


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