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

相關文章
- PHP 變量
- PHP 數(shù)據類型
- 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ù)