MYSQLI

MYSQLI

MySqli is database driver for connection with MySQL database.

Connect MySQL database using PHP script  

<?php

mysqli_connect(hostname‘,’username‘,’password‘,’database_name);

?>

Here mysqli_connect is inbuild function of php for connection with MySql database.

In this function, you required four parameters as shown in above script.

  • hostname: your database hosting name if in your computer then write localhost for local database use else writes database provider name.
  • username: your database username. if in the local server then write root.
  • password: Your database password. if in the local server then leave is blank. As shown in blow script
  • database_name: name of your database.

<?php

// Local connection script

$connection=mysql_connect(‘localhost’,’root’,”,’test_db’);

if(mysqli_connect_errno()){    //

echo “Error : Database could not connect : “. mysqli_connect_error(); // if databse not connected then show error

}

?>

Next Create Database,  mysqli_query();