PHP mysqli_connect() Function is used to open a new connection to the MySQL server. mysqli_connect() establishes a connection with MySQL server and returns the connection as an object.
PHP Version : PHP 5, PHP 7
Syntax for mysqli_connect:
According to Procedural
$link=mysqli_connect($SERVER,$USERNAME,$PASSWORD,$DATABASE,$PORT,$SOCKET) or die(mysqli_error()) ;
According to Object oriented
$mysqli -> new mysqli($SERVER,$USERNAME,$PASSWORD,$DATABASE,$PORT,$SOCKET);
Parameter,
Parameter | Description |
$SERVER | Required. It specifies server / host name. |
$USERNAME | Required. It specifies username of mysql. |
$PASSWORD | Required. It specifies password of mysql. |
$DATABASE | Optional. It specifies database name. |
$PORT | Optional. It specifies port number of mysql. |
$SOCKET | Optional. It specifies socket to be used. |
Return values for mysqli_connect:
It returns an object representing the connection to the MySQL server. Otherwise it returns false, if connection is failed.
Comments