PHP mysqli_connect() 函數(shù)
PHP mysqli_connect() 函數(shù)
實(shí)例
打開一個(gè)到 MySQL 服務(wù)器的新的連接:
<?php
$con=mysqli_connect("localhost","wrong_user","my_password","my_db");
// 檢查連接
if (!$con)
{
die("連接錯(cuò)誤: " . mysqli_connect_error());
}
?>
$con=mysqli_connect("localhost","wrong_user","my_password","my_db");
// 檢查連接
if (!$con)
{
die("連接錯(cuò)誤: " . mysqli_connect_error());
}
?>
定義和用法
mysqli_connect() 函數(shù)打開一個(gè)到 MySQL 服務(wù)器的新的連接。
語(yǔ)法
mysqli_connect(host,username,password,dbname,port,socket);
參數(shù) | 描述 |
---|---|
host | 可選。規(guī)定主機(jī)名或 IP 地址。 |
username | 可選。規(guī)定 MySQL 用戶名。 |
password | 可選。規(guī)定 MySQL 密碼。 |
dbname | 可選。規(guī)定默認(rèn)使用的數(shù)據(jù)庫(kù)。 |
port | 可選。規(guī)定嘗試連接到 MySQL 服務(wù)器的端口號(hào)。 |
socket | 可選。規(guī)定 socket 或要使用的已命名 pipe。 |
技術(shù)細(xì)節(jié)
返回值: | 返回一個(gè)代表到 MySQL 服務(wù)器的連接的對(duì)象。 |
---|---|
PHP 版本: | 5+ |

相關(guān)文章
- PHP 變量
- PHP 數(shù)據(jù)類型
- PHP date() 函數(shù)
- PHP 文件處理
- PHP Secure E-mails
- PHP 異常處理
- PHP array() 函數(shù)
- PHP array_intersect_uassoc() 函數(shù)
- PHP array_key_exists() 函數(shù)
- PHP array_key_first() 函數(shù)
- PHP array_merge() 函數(shù)
- PHP array_merge_recursive() 函數(shù)
- PHP array_product() 函數(shù)
- PHP array_walk() 函數(shù)
- PHP arsort() 函數(shù)
- PHP asort() 函數(shù)
- PHP krsort() 函數(shù)
- PHP pos() 函數(shù)
- PHP prev() 函數(shù)
- PHP HTTP 函數(shù)