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
2. Pass the Query$connection=mysqli_connect("localhost","root","enter password","enter database");
$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
4.Close the connectionwhile($rows = mysqli_fetch_array($data)) { echo $rows['Fname'] . " " . $row['Lname']; echo "<br>";}
In this code we must have to open the connection and close the connection to exchange the data between database and php application .mysqli_close($con);
0 comments:
Post a Comment