Tuesday, August 5, 2014

How to Connect with database in PHP

PHP is the server side scripting language which is used in modifying ,add validating script in the html webpage. The code for PHP language is present at server nobody can see the coding of PHP file.PHP is the most popular language and used in most of the web sites to reduce the coding of the whole web sites.

There are Four steps to connect with database in php
1.Create the connection
$connection=mysqli_connect("localhost","root","enter password","enter database");
 2. Pass the Query

$data = mysqli_query($connection,"Write the Query here");
3.Retrieve the data
    suppose we want to retrieve the  data from table having the column name Fname and Lname.Here we use while loop to retrieve the no of rows from the table

while($rows = mysqli_fetch_array($data)) {   echo $rows['Fname'] . " " . $row['Lname'];   echo "<br>";}
4.Close the connection
In this code we must have to open the connection and close the connection to exchange the data between database and php application .
Categories: , ,


Post a Comment