本文整理汇总了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;
}
示例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;
}
示例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;
}
示例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;
}
示例5: dbConnect
function dbConnect()
{
//Connessione DB
$mysqli = new mysqli();
$mysqli->connect(_DB_SERVER, _DB_USER, _DB_PASSWORD, _DB_NAME);
return $mysqli;
}
示例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);
}
}
示例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']);
}
示例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;
}
示例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++;
}
示例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;
}
}
示例11: ConGestionDC
function ConGestionDC()
{
try {
$con = new mysqli();
$con->connect('localhost', 'root', '', 'gestiondc');
return $con;
} catch (Exception $ex) {
return "Error: " . $ex->getMessage();
}
}
示例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);
}
示例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];
}
}
示例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";
}
示例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;
}