PHP mysqli_connect() Function (original) (raw)

Last Updated : 12 Aug, 2024

The mysqli_connect() function in **PHP is a fundamental tool for establishing a connection to a MySQL database. This function is crucial for PHP applications that need to interact with MySQL databases, enabling them to execute queries, retrieve data, and perform various database operations.

In this article, We will learn about the **PHP mysqli_connect() Function in detail by understanding various examples and so on.

PHP mysqli_connect() Function

**Syntax:

mysqli_connect ( "host", "username", "password", "database_name" );

Parameter Values

**Return Value:

**Program: Below is the implementation of **mysqli_connect() function.

php `

`

**Output:

Database Connection Successfully.

We can also use the **die() method to terminate the program with a message if the connection fails.

**Program: Below is the implementation of the die() method with the mysqli_connect() method.

PHP `

`

**Output:

Database Connection Successfully.

Conclusion

The mysqli_connect() function is essential for establishing a connection between PHP scripts and a MySQL database. By correctly configuring its parameters, developers can securely and efficiently interact with MySQL databases, leveraging the power of MySQLi for a wide range of database operations.