Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App
geeksforgeeks
Browser
Continue

Related Articles

PHP mysqli_connect() Function

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

The mysqli_connect() function in PHP is used to connect you to the database. In the previous version of the connection mysql_connect() was used for connection and then there comes mysqli_connect() where i means improved version of connection and is more secure than mysql_connect().
Syntax: 
 

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

Parameters used: 
 

  • host: It is optional and it specify the host name or IP address. In case of local server localhost is used as a general keyword to connect local server and run the program.
  • username: It is optional and it specify mysql username. In local server username is root.
  • Password: It is optional and it specify mysql password.
  • database_name: It is database name where operation perform on data. It also optional.

Return values: 
 

  • It returns an object which represent MySql connection. If connection failed then it return FALSE.

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

php




<?php
    mysqli_connect("localhost", "root", "", "GFG");
  
    if(mysqli_connect_error())
        echo "Connection Error.";
    else
        echo "Database Connection Successfully.";
?>

Output: 
 

Database Connection Successfully.

 

My Personal Notes arrow_drop_up
Last Updated : 31 Mar, 2023
Like Article
Save Article
Similar Reads
Related Tutorials