Posted by: Sourav | March 29, 2011

Database operation in php


<?php
//create a database connection
$connection=mysql_connect(“localhost”,”root”,”123456″);
if(!$connection){
die(“database connection failed:”.mysql_error());
}
//select the database to use
$db_select=mysql_select_db(“sourav_corp”,$connection);
if(!$db_select){
die(“database connection failed:”.mysql_error());
}
?>
<html>
    <head>
        <title>
            Database Connection
        </title>
    </head>
    <body>
        <?php
        //perform a database query
        $result=mysql_query(“select * from contents”,$connection);
        if(!$result){
die(“database connection failed:”.mysql_error());
}
//returning data
while($row=mysql_fetch_array($result)){
    echo $row[1].” “.$row[2].” “.$row[3].” “.$row[4].”<br />”;
}
   
        ?>
        </body>
</html>
<?php
//close the connection
mysql_close($connection);
?>

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: