Thursday 15 May 2014

How to connect Database by PHP

The Syntax for connecting to the database is

mysqli_connect(host,username,password,dbname);
where  host is the host name of the computer, basically we chose localhost
           username is the database username i.e. root
           password is the password to access the database;
           dbname  is the name of the database file


<?php
//for connecting to database named book
$con=mysqli_connect("localhost","root"," ","book");

// error reporting
if (mysqli_connect_errno()) {
  echo "Failed to connect  " . mysqli_connect_error();
}
?>

No comments:

Post a Comment