PHP mysqli_connect()Functions

PHP MySQLi 参考手册PHP MySQLi Reference Manual

Examples

Open a new connection to a MySQL server:

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

Definition and Usage

The mysqli_connect() function opens a new connection to a MySQL server.


Syntax

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

Parameters Description
host Optional. Specifies the hostname or IP address.
username Optional. Specifies the MySQL username.
password Optional. Specifies the MySQL password.
dbname Optional. Specifies the database to use by default.
port Optional. Specifies the port number to attempt to connect to the MySQL server.
socket Optional. Specifies the socket or named pipe to use.

Technical Details

Return value: Returns an object representing the connection to the MySQL server.
PHP Version: 5+


PHP MySQLi 参考手册PHP MySQLi Reference Manual Other Extensions