PHP mysqli_connect() Function Last Updated : 12 Aug, 2024 Comments Improve Suggest changes Like Article Like Report 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() FunctionThe mysqli_connect() function in PHP is used to establish a connection to a MySQL database. This function initiates a connection to the MySQL server and returns a connection object on success, or FALSE failure. It allows PHP scripts to interact with a MySQL database to perform various operations like querying, inserting, updating, and deleting data.Syntax: mysqli_connect ( "host", "username", "password", "database_name" );host: The hostname or IP address of the MySQL server.username: The username to access the MySQL server.password: The password associated with the given username.database (optional): The name of the database to select upon connection.port (optional): The port number to connect to the MySQL server. Default is 3306.socket (optional): The socket or named pipe to use for the connection.Parameter Valueshost: A string representing the MySQL server's address.username: A string representing the username for MySQL authentication.password: A string representing the password for MySQL authentication.database: A string representing the database name to use (optional).port: An integer representing the port number (optional).socket: A string representing the socket or pipe for the connection (optional).Return Value:It returns an object which represents the MySql connection. If the connection failed then it returns 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.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 <?php mysqli_connect("localhost", "root", "", "GFG") or die("Connection Unsuccessfull"); // If the connection is successfull then // the program does not terminates // and the following message is displayed. echo "Connection Successfull"; ?> Output:Database Connection Successfully.ConclusionThe 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. Comment More infoAdvertise with us Next Article PHP mysqli_connect() Function R RahulUniyal Follow Improve Article Tags : PHP Similar Reads PHP | mysqli_close() Function MySQLi Procedural procedure: To close the connection in mysql database we use php function mysqli_close() which disconnect from database. It require a parameter which is a connection returned by the mysql_connect function. Syntax: mysqli_close(conn); If the parameter is not specified in mysqli_close 2 min read PHP | mysqli_error() Function The mysqli_error() function is used to return the error in the most recent MySQL function call that failed. If there are multiple MySQL function calls, the error in the last statement is the one that is pointed out by the function. Syntax: mysqli_error("database_name") Parameters: This function acce 1 min read PHP | ftp_connect() function The ftp_connect() function is an inbuilt function in PHP which is used to create a new connection to the specified FTP server or Host. When connection is successful then only other FTP functions can be run against the server. Syntax: ftp_connect( $ftp_host, $ftp_port, $timeout ); Parameter: This fu 2 min read PHP | mysqli_fetch_array() Function The mysqli_fetch_array() function is used to fetch rows from the database and store them as an array. The array can be fetched as an associative array, as a numeric array or both. Associative arrays are the arrays where the indexes are the names of the individual columns of the table. On the other h 2 min read PHP | mysqli_ping() Function The mysqli_ping() function is used to ping a server connection. That is it is used to check if a host is reachable on an IP network or not. This function also tries to reconnect if an existing server connection is lost. To use this function, it is mandatory to first set up the connection with the My 2 min read PHP | ftp_ssl_connect() Function The ftp_ssl_connect() function is an inbuilt function in PHP which opens a secure SSL-FTP connection. FTP functions can be run against the server while the connection is open. It opens an explicit SSL-FTP connection to the host specified in parameter. It will succeed even if the server's certificate 2 min read PHP | connection_status() Function The connection_status() function is an inbuilt function in PHP which returns the current connection status. Syntax: int connection_status( void ) Parameters: This function doesn't accept any parameters. Return Value: This function returns the connection status bitfield. The possible values of return 2 min read PHP | mysqli_num_rows() Function The mysqli_num_rows() function is an inbuilt function in PHP which is used to return the number of rows present in the result set. It is generally used to check if data is present in the database or not. To use this function, it is mandatory to first set up the connection with the MySQL database. Sy 2 min read PHP | ftp_login() function The ftp_login() function is an inbuilt function in PHP which is used to login to an established FTP connection. Syntax: ftp_login( $ftp_connection, $ftp_username, $ftp_userpass ); Parameter: This function accepts three parameters as mentioned above and described below: $ftp_connection: It is require 2 min read PHP | mysqli_real_escape_string() Function The mysqli_real_escape_string() function is an inbuilt function in PHP which is used to escape all special characters for use in an SQL query. It is used before inserting a string in a database, as it removes any special characters that may interfere with the query operations. When simple strings ar 2 min read Like