當前位置: 首頁>>代碼示例>>PHP>>正文


PHP mysqli::connect方法代碼示例

本文整理匯總了PHP中mysqli::connect方法的典型用法代碼示例。如果您正苦於以下問題:PHP mysqli::connect方法的具體用法?PHP mysqli::connect怎麽用?PHP mysqli::connect使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在mysqli的用法示例。


在下文中一共展示了mysqli::connect方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: connect

 /**
  * Connect
  * @param string $host
  * @param string $user
  * @param string $paswd
  * @param string $db
  * @param int $port
  * @return mixed
  */
 public function connect($host, $user, $paswd, $db, $port = self::DEFAULT_PORT)
 {
     $port = (int) $port;
     $res = @$this->conn->connect($host, $user, $paswd, $db, $port);
     if (0 !== mysqli_connect_errno($this->conn)) {
         throw new Mage_DB_Exception(mysqli_connect_error($this->conn));
     }
     return $res;
 }
開發者ID:buttasg,項目名稱:cowgirlk,代碼行數:18,代碼來源:Mysqli.php

示例2: connect

 public function connect($host = "92.222.29.95", $user = "iwebRayane", $paswd = "CestLeProjet2.0", $db = "projetiweb")
 {
     //$port = (int) $port;
     $res = @$this->conn->connect($host, $user, $paswd, $db, 3306);
     if (0 !== mysqli_connect_errno($this->conn)) {
         //throw new mysqli_connect_error($this->conn);
         echo 'Erreur de connection<br>';
         print_r(error_get_last());
         echo "<br>" . mysqli_connect_errno($this->conn) . ": " . mysqli_connect_error($this->conn) . "<br>" . $this->conn->connect_errno . " | " . $this->conn->connect_error;
     }
     return $res;
 }
開發者ID:Sup-Galilee-AIR-2014-2017,項目名稱:Teacher-Research_Project,代碼行數:12,代碼來源:Manager_base.php

示例3: connect

 /**
  * 參數為了兼容parent類,代碼不會使用傳入的參數作為配置
  * @param null $_host
  * @param null $user
  * @param null $password
  * @param null $database
  * @param null $port
  * @param null $socket
  * @return bool
  */
 function connect($_host = null, $user = null, $password = null, $database = null, $port = null, $socket = null)
 {
     $db_config =& $this->config;
     $host = $db_config['host'];
     if (!empty($db_config['persistent'])) {
         $host = 'p:' . $host;
     }
     if (isset($db_config['passwd'])) {
         $db_config['password'] = $db_config['passwd'];
     }
     if (isset($db_config['dbname'])) {
         $db_config['name'] = $db_config['dbname'];
     } elseif (isset($db_config['database'])) {
         $db_config['name'] = $db_config['database'];
     }
     parent::connect($host, $db_config['user'], $db_config['password'], $db_config['name'], $db_config['port']);
     if ($this->connect_errno) {
         trigger_error("mysqli connect to server[{$host}:{$db_config['port']}] failed: " . mysqli_connect_error(), E_USER_WARNING);
         return false;
     }
     if (!empty($db_config['charset'])) {
         $this->set_charset($db_config['charset']);
     }
     return true;
 }
開發者ID:matyhtf,項目名稱:swoole_framework,代碼行數:35,代碼來源:MySQLi.php

示例4: connect

 public function connect($host = NULL, $user = NULL, $password = NULL, $database = NULL, $port = NULL, $socket = NULL)
 {
     $config = $this->config;
     if ($config['host'] === 'localhost') {
         @parent::connect($config['host'], $config['user'], $config['password'], $config['database'], 0, $config['socket']);
     } else {
         @parent::connect($config['host'], $config['user'], $config['password'], $config['database'], $config['port']);
     }
     if ($this->connect_errno) {
         Log::prn_log(ERROR, "database connect failed: " . $this->connect_error . "!");
         return false;
     }
     Log::prn_log(INFO, "database connect ok ({$config['host']},{$config['port']})!");
     if (isset($config['charset'])) {
         Log::prn_log(INFO, "set charset names {$config['charset']}");
         $this->query("set names {$config['charset']}");
     }
     if (isset($config['sqls'])) {
         $sqls = explode(";", $config['sqls']);
         foreach ($sqls as $sql) {
             Log::prn_log(INFO, "{$sql}");
             $this->query($sql);
         }
     }
     return true;
 }
開發者ID:loder,項目名稱:asf,代碼行數:26,代碼來源:mysql.php

示例5: dbConnect

function dbConnect()
{
    //Connessione DB
    $mysqli = new mysqli();
    $mysqli->connect(_DB_SERVER, _DB_USER, _DB_PASSWORD, _DB_NAME);
    return $mysqli;
}
開發者ID:alessiobusonera,項目名稱:amm2015,代碼行數:7,代碼來源:php_functions.php

示例6: __construct

 private function __construct()
 {
     $this->ccnn = parent::connect($this->host, $this->user, $this->pass, $this->ddbb);
     if ($this->connect_errno) {
         die('Error # ' . $this->connect_errno . ': ' . $this->connect_error);
     }
 }
開發者ID:Cristian9,項目名稱:AdobeConnect,代碼行數:7,代碼來源:accdb.php

示例7: connect

 function connect()
 {
     $db_config =& $this->config;
     parent::connect($db_config['host'], $db_config['user'], $db_config['password'], $db_config['dbname']);
     if (mysqli_connect_errno()) {
         exit("Connect failed: %s\n" . mysqli_connect_error());
     }
     $this->set_charset($db_config['charset']);
 }
開發者ID:superwmh,項目名稱:swoole,代碼行數:9,代碼來源:MySQL2.class.php

示例8: initializeDbConnection

 /**
  * get database connection infos and connect to the database
  *
  * @return mysqli
  */
 public static function initializeDbConnection()
 {
     $dbPath = config_get('hostname');
     $dbUser = config_get('db_username');
     $dbPass = config_get('db_password');
     $dbName = config_get('database_name');
     $mysqli = new mysqli($dbPath, $dbUser, $dbPass, $dbName);
     $mysqli->connect($dbPath, $dbUser, $dbPass, $dbName);
     return $mysqli;
 }
開發者ID:Cre-ator,項目名稱:Whiteboard.Menu-Plugin,代碼行數:15,代碼來源:wmApi.php

示例9: createConnection

 /**
  * create mysql connection
  */
 protected function createConnection()
 {
     $config = $this->config;
     $db = new \mysqli();
     $db->connect($config['host'], $config['user'], $config['password'], $config['database'], $config['port']);
     $db_sock = swoole_get_mysqli_sock($db);
     swoole_event_add($db_sock, array($this, 'onSQLReady'));
     $this->idle_pool[] = array('object' => $db, 'socket' => $db_sock);
     $this->connection_num++;
 }
開發者ID:silentred,項目名稱:learning-path,代碼行數:13,代碼來源:MySQL.php

示例10: connectDb

 /**
  * Restituisce una connessione funzionante al db
  * @return \mysqli una connessione funzionante al db dell'applicazione,
  * null in caso di errore
  */
 public function connectDb()
 {
     $mysqli = new mysqli();
     $mysqli->connect(Settings::$db_host, Settings::$db_user, Settings::$db_password, Settings::$db_name);
     if ($mysqli->errno != 0) {
         return null;
     } else {
         return $mysqli;
     }
 }
開發者ID:nadiajolanda,項目名稱:esAMM2014,代碼行數:15,代碼來源:Db.php

示例11: ConGestionDC

function ConGestionDC()
{
    try {
        $con = new mysqli();
        $con->connect('localhost', 'root', '', 'gestiondc');
        return $con;
    } catch (Exception $ex) {
        return "Error: " . $ex->getMessage();
    }
}
開發者ID:dice9030,項目名稱:GestionLogistico,代碼行數:10,代碼來源:conexiones.php

示例12: connect

 public function connect($host = null, $user = null, $psw = null, $dbname = null, $port = null, $socket = null, $tbname = null)
 {
     parent::connect($host, $user, $psw, $dbname, $port, $socket);
     $host != null && ($this->_host = $host);
     $port != null && ($this->_port = $port);
     $user != null && ($this->_user = $user);
     $psw != null && ($this->_psw = $psw);
     $dbname != null && ($this->_dbname = $dbname);
     $tbname != null && ($this->_tbname = $tbname);
     $socket != null && ($this->_socket = $socket);
 }
開發者ID:renwuxun,項目名稱:core,代碼行數:11,代碼來源:MysqliConn.php

示例13: f

 public static function f($connection)
 {
     list($host, $user, $pass, $db) = explode(':', $connection);
     if (empty(self::$instance_f[$connection])) {
         $i = new mysqli();
         $i->connect($host, $user, $pass, $db, true);
         self::$instance_f[$connection] = $i;
         return $i;
     } else {
         return self::$instance_f[$connection];
     }
 }
開發者ID:Git-Host,項目名稱:sms,代碼行數:12,代碼來源:mysqli.class.php

示例14: onStart

 function onStart($serv)
 {
     $this->serv = $serv;
     for ($i = 0; $i < $this->pool_size; $i++) {
         $db = new mysqli();
         $db->connect('172.16.1.19', 'test', 'test', '1188test');
         $db_sock = swoole_get_mysqli_sock($db);
         swoole_event_add($db_sock, array($this, 'onSQLReady'));
         $this->idle_pool[] = array('mysqli' => $db, 'db_sock' => $db_sock, 'fd' => 0);
     }
     echo "Server: start.Swoole version is [" . SWOOLE_VERSION . "]\n";
 }
開發者ID:silentred,項目名稱:learning-path,代碼行數:12,代碼來源:mysql_proxy_server.php

示例15: connect

 function connect()
 {
     $db_config =& $this->config;
     parent::connect($db_config['host'], $db_config['user'], $db_config['passwd'], $db_config['name']);
     if (mysqli_connect_errno()) {
         trigger_error("Mysqli connect failed: %s\n" . mysqli_connect_error());
         return false;
     }
     if (!empty($db_config['charset'])) {
         $this->set_charset($db_config['charset']);
     }
     return true;
 }
開發者ID:jinguanio,項目名稱:swoole_websocket,代碼行數:13,代碼來源:MySQLi.php


注:本文中的mysqli::connect方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。