
In PHP we can connect to database by using five simple steps as demonstrated below :
<?php //Step-1 : Create a database connection $connection=mysql_connect("localhost","root","root"); if(!$connection) { die("Database Connection error" . mysql_error()); } //Step-2 : Select a database to use $db=mysql_select_db("widget_corp",$connection); if(!$db) { die("Database Selection error" . mysql_error()); } //Step 3 : Perform database Queury $result=mysql_query("select * from subjects",$connection); if(!$result) { die("No rows Fetch" . mysql_error()); } //Step 4 : Use returned data while($row=mysql_fetch_array($result)) { //echo $row[1]." ".$row[2]; echo $row["menu_name"]." ".$row["position"]; } //Step 5 : Close Connection mysql_close($connection); ?>In the above code I have demonstrated 5 simple steps for connecting to database. Hope it will be useful for you. Feel free to post your ideas in the comments below.
0 comments:
Post a Comment
Note: only a member of this blog may post a comment.