,
Share with your friends 

connect to the database with php.

0 ratings Views 131 
Author: sirin (sirin k)  View Profile |  View other solutions by this author

Question / Problem


How do i connectand fetch data from database using php?

Solution

<?php
$db=mysql_connect("localhost",'username','password')or die("Cannot connect");
mysql_select_db('db_name',$db);
$query="select * from tablename";
$result=mysql_query($query.$db);
 while($row=mysql_fetch_array($result))
         {
           echo $row['field_name1'];
          
           echo $row['field_name2'];
           echo $row['field_name3'];


        
           echo $row['field_nameN'];
         }
?>

Applies to

PHP

Rank It

Login to rank it

Report


Advertisement