Pages

Subscribe:

Ads 468x60px

Sunday, July 25, 2010

How to write a Database Connection Code in PHP?

In PHP, you can easily write database connection code. Actually when you want to make any dynamic site using PHP programming language then the first question before doing anything that will arise into your mind is: "How can I make database and how to link with database". In the following, I write a database connection code that will become very simple and easy.
For this you will have to use MySQL database where you can make database easily. Then just follow my code:

<?php
$link = mysql_connect('localhost', 'root', '') or die("Couldn't connect to the database.");
$dbname = mysql_select_db('your_database_name') or die("Couldn't select the database");
?>


The above code will work on local server, but when you will use web server, then use a username in case of 'root' and a password in case of this blank space  '  '

0 comments:

Post a Comment