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


PHP MySQLi::real_connect方法代码示例

本文整理汇总了PHP中MySQLi::real_connect方法的典型用法代码示例。如果您正苦于以下问题:PHP MySQLi::real_connect方法的具体用法?PHP MySQLi::real_connect怎么用?PHP MySQLi::real_connect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MySQLi的用法示例。


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

示例1: connect

 public function connect($host = '127.0.0.1', $username = '', $passwd = '', $dbname = '', $port = 3306, $socket = '')
 {
     if (!parent::real_connect($this->cfg['host'], $this->cfg['username'], $this->cfg['password'], null, $this->cfg['port'], $this->cfg['socket'], $this->cfg['flags'])) {
         throw new Poodle_SQL_Exception($this->connect_error, $this->connect_errno, Poodle_SQL_Exception::NO_CONNECTION);
     }
     $v41 = version_compare($this->server_version, '4.1', '>=');
     if (!$v41) {
         $this->cfg['charset'] = 'latin1';
     }
     $this->select_db();
     $this->set_charset();
     # dev.mysql.com/doc/refman/5.1/en/time-zone-support.html
     parent::query('SET time_zone = \'+0:00\'');
     parent::query('SET SESSION sql_mode = \'TRADITIONAL,ONLY_FULL_GROUP_BY,NO_AUTO_VALUE_ON_ZERO,PIPES_AS_CONCAT\'');
     if ($this->cfg['storage_engine']) {
         parent::query('SET ' . ($v41 ? 'storage_engine' : 'table_type') . '=' . $this->cfg['storage_engine']);
     }
 }
开发者ID:cbsistem,项目名称:nexos,代码行数:18,代码来源:mysqli.php

示例2: db_connect

    /**
     * Database connection
     *
     * @param	bool	$persistent
     * @return	object
     */
    public function db_connect($persistent = FALSE)
    {
        // Do we have a socket path?
        if ($this->hostname[0] === '/') {
            $hostname = NULL;
            $port = NULL;
            $socket = $this->hostname;
        } else {
            // Persistent connection support was added in PHP 5.3.0
            $hostname = $persistent === TRUE && is_php('5.3') ? 'p:' . $this->hostname : $this->hostname;
            $port = empty($this->port) ? NULL : $this->port;
            $socket = NULL;
        }
        $client_flags = $this->compress === TRUE ? MYSQLI_CLIENT_COMPRESS : 0;
        $this->_mysqli = mysqli_init();
        $this->_mysqli->options(MYSQLI_OPT_CONNECT_TIMEOUT, 10);
        if (isset($this->stricton)) {
            if ($this->stricton) {
                $this->_mysqli->options(MYSQLI_INIT_COMMAND, 'SET SESSION sql_mode = CONCAT(@@sql_mode, ",", "STRICT_ALL_TABLES")');
            } else {
                $this->_mysqli->options(MYSQLI_INIT_COMMAND, 'SET SESSION sql_mode =
					REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(
					@@sql_mode,
					"STRICT_ALL_TABLES,", ""),
					",STRICT_ALL_TABLES", ""),
					"STRICT_ALL_TABLES", ""),
					"STRICT_TRANS_TABLES,", ""),
					",STRICT_TRANS_TABLES", ""),
					"STRICT_TRANS_TABLES", "")');
            }
        }
        if (is_array($this->encrypt)) {
            $ssl = array();
            empty($this->encrypt['ssl_key']) or $ssl['key'] = $this->encrypt['ssl_key'];
            empty($this->encrypt['ssl_cert']) or $ssl['cert'] = $this->encrypt['ssl_cert'];
            empty($this->encrypt['ssl_ca']) or $ssl['ca'] = $this->encrypt['ssl_ca'];
            empty($this->encrypt['ssl_capath']) or $ssl['capath'] = $this->encrypt['ssl_capath'];
            empty($this->encrypt['ssl_cipher']) or $ssl['cipher'] = $this->encrypt['ssl_cipher'];
            if (!empty($ssl)) {
                if (isset($this->encrypt['ssl_verify'])) {
                    if ($this->encrypt['ssl_verify']) {
                        defined('MYSQLI_OPT_SSL_VERIFY_SERVER_CERT') && $this->_mysqli->options(MYSQLI_OPT_SSL_VERIFY_SERVER_CERT, TRUE);
                    } elseif (defined('MYSQLI_CLIENT_SSL_DONT_VERIFY_SERVER_CERT')) {
                        $this->_mysqli->options(MYSQLI_CLIENT_SSL_DONT_VERIFY_SERVER_CERT, TRUE);
                    }
                }
                $client_flags |= MYSQLI_CLIENT_SSL;
                $this->_mysqli->ssl_set(isset($ssl['key']) ? $ssl['key'] : NULL, isset($ssl['cert']) ? $ssl['cert'] : NULL, isset($ssl['ca']) ? $ssl['ca'] : NULL, isset($ssl['capath']) ? $ssl['capath'] : NULL, isset($ssl['cipher']) ? $ssl['cipher'] : NULL);
            }
        }
        if (@$this->_mysqli->real_connect($hostname, $this->username, $this->password, $this->database, $port, $socket, $client_flags)) {
            // Prior to version 5.7.3, MySQL silently downgrades to an unencrypted connection if SSL setup fails
            if ($client_flags & MYSQLI_CLIENT_SSL && version_compare($this->_mysqli->client_info, '5.7.3', '<=') && empty($this->_mysqli->query("SHOW STATUS LIKE 'ssl_cipher'")->fetch_object()->Value)) {
                $this->_mysqli->close();
                $message = 'MySQLi was configured for an SSL connection, but got an unencrypted connection instead!';
                log_message('error', $message);
                return $this->db->db_debug ? $this->db->display_error($message, '', TRUE) : FALSE;
            }
            return $this->_mysqli;
        }
        return FALSE;
    }
开发者ID:tastyigniter,项目名称:tastyigniter,代码行数:68,代码来源:mysqli_driver.php

示例3: connect

    /**
     * Connect to the database.
     *
     * @param bool $persistent
     * @return mixed
     */
    public function connect($persistent = false)
    {
        // Do we have a socket path?
        if ($this->hostname[0] === '/') {
            $hostname = null;
            $port = null;
            $socket = $this->hostname;
        } else {
            $hostname = $persistent === true ? 'p:' . $this->hostname : $this->hostname;
            $port = empty($this->port) ? null : $this->port;
            $socket = null;
        }
        $client_flags = $this->compress === true ? MYSQLI_CLIENT_COMPRESS : 0;
        $this->mysqli = mysqli_init();
        $this->mysqli->options(MYSQLI_OPT_CONNECT_TIMEOUT, 10);
        if (isset($this->strictOn)) {
            if ($this->strictOn) {
                $this->mysqli->options(MYSQLI_INIT_COMMAND, 'SET SESSION sql_mode = CONCAT(@@sql_mode, ",", "STRICT_ALL_TABLES")');
            } else {
                $this->mysqli->options(MYSQLI_INIT_COMMAND, 'SET SESSION sql_mode =
					REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(
					@@sql_mode,
					"STRICT_ALL_TABLES,", ""),
					",STRICT_ALL_TABLES", ""),
					"STRICT_ALL_TABLES", ""),
					"STRICT_TRANS_TABLES,", ""),
					",STRICT_TRANS_TABLES", ""),
					"STRICT_TRANS_TABLES", "")');
            }
        }
        if (is_array($this->encrypt)) {
            $ssl = [];
            empty($this->encrypt['ssl_key']) or $ssl['key'] = $this->encrypt['ssl_key'];
            empty($this->encrypt['ssl_cert']) or $ssl['cert'] = $this->encrypt['ssl_cert'];
            empty($this->encrypt['ssl_ca']) or $ssl['ca'] = $this->encrypt['ssl_ca'];
            empty($this->encrypt['ssl_capath']) or $ssl['capath'] = $this->encrypt['ssl_capath'];
            empty($this->encrypt['ssl_cipher']) or $ssl['cipher'] = $this->encrypt['ssl_cipher'];
            if (!empty($ssl)) {
                if (isset($this->encrypt['ssl_verify'])) {
                    if ($this->encrypt['ssl_verify']) {
                        defined('MYSQLI_OPT_SSL_VERIFY_SERVER_CERT') && $this->mysqli->options(MYSQLI_OPT_SSL_VERIFY_SERVER_CERT, true);
                    } elseif (defined('MYSQLI_CLIENT_SSL_DONT_VERIFY_SERVER_CERT')) {
                        $this->mysqli->options(MYSQLI_CLIENT_SSL_DONT_VERIFY_SERVER_CERT, true);
                    }
                }
                $client_flags |= MYSQLI_CLIENT_SSL;
                $this->mysqli->ssl_set(isset($ssl['key']) ? $ssl['key'] : null, isset($ssl['cert']) ? $ssl['cert'] : null, isset($ssl['ca']) ? $ssl['ca'] : null, isset($ssl['capath']) ? $ssl['capath'] : null, isset($ssl['cipher']) ? $ssl['cipher'] : null);
            }
        }
        if ($this->mysqli->real_connect($hostname, $this->username, $this->password, $this->database, $port, $socket, $client_flags)) {
            // Prior to version 5.7.3, MySQL silently downgrades to an unencrypted connection if SSL setup fails
            if ($client_flags & MYSQLI_CLIENT_SSL && version_compare($this->mysqli->client_info, '5.7.3', '<=') && empty($this->mysqli->query("SHOW STATUS LIKE 'ssl_cipher'")->fetch_object()->Value)) {
                $this->mysqli->close();
                $message = 'MySQLi was configured for an SSL connection, but got an unencrypted connection instead!';
                log_message('error', $message);
                if ($this->db->db_debug) {
                    throw new DatabaseException($message);
                }
                return false;
            }
            if (!$this->mysqli->set_charset($this->charset)) {
                log_message('error', "Database: Unable to set the configured connection charset ('{$this->charset}').");
                $this->mysqli->close();
                if ($this->db->debug) {
                    throw new DatabaseException('Unable to set client connection character set: ' . $this->charset);
                }
                return false;
            }
            return $this->mysqli;
        }
        return false;
    }
开发者ID:titounnes,项目名称:CodeIgniter4,代码行数:78,代码来源:Connection.php

示例4: init

 private function init()
 {
     $handle = new MySQLi();
     $handle->init();
     $handle->options(MYSQLI_OPT_CONNECT_TIMEOUT, 5);
     if (@$handle->real_connect(_DBMS_HOST, _DBMS_LOGIN, _DBMS_PASS, _DBMS_DB) === FALSE) {
         throw new DatabaseException($handle->connect_error);
     }
     if (!$handle->select_db(_DBMS_DB)) {
         throw new DatabaseException('Can\'t connect to Database !');
     }
     return $handle;
 }
开发者ID:Korko,项目名称:RiskOnline,代码行数:13,代码来源:MySQL_DBMS.php


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