MySQLi Connection with PHP Script

PHP provides mysqli_connect() function to open a database connection. This function takes six parameters and returns the successful connection as an object. If the connection failed to establish, then the function returns the boolean value False.

Example :-

$con = new mysqli($host, $username, $passwd, $dbname);

You can disconnect from the MySQLi database using the MySQLi close function.

Statement to close connetion :-

$con -> close();

PHP example of connecting to a MySQLi server –

      <title>Connecting to MySQLi Server</title>
         $host = "localhost";
   $username  = "root";
   $password = "password";
   $dbname = "mydb";
   $con = new mysqli($host, $username, $password, $dbname);
      print("Connection not established. ");
      print("Connection Established Successfully");
   $con -> close();

Leave a Reply

Your email address will not be published. Required fields are marked *