Latest web development tutorials

PHP mysqli_connect () function

PHP MySQLi Reference Manual PHP MySQLi Reference Manual

Examples

Open a new connection to the MySQL server:

<? php
$ con = mysqli_connect ( "localhost" , "wrong_user", "my_password", "my_db");
// Check the connection
if (! $ con)
{
die ( "Connection Error:" mysqli_connect_error ().);
}
?>

Definition and Usage

mysqli_connect () function to open a new connection to the MySQL server.


grammar

mysqli_connect( host,username,password,dbname,port,socket ) ;

参数 描述
host 可选。规定主机名或 IP 地址。
username 可选。规定 MySQL 用户名。
password 可选。规定 MySQL 密码。
dbname 可选。规定默认使用的数据库。
port 可选。规定尝试连接到 MySQL 服务器的端口号。
socket 可选。规定 socket 或要使用的已命名 pipe。

technical details

return value: Return to a representative to object to connect the MySQL server.
PHP version: 5+


PHP MySQLi Reference Manual PHP MySQLi Reference Manual