Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

How to connect a database in Php

                    Connecting the Database in Php plays an important role. As I already mentioned in my previous article called introduction to php that connecting database comes under the categories of Dynamic. Mean while these connections are performed in two ways and the first one with example is as follows:-

<?
……………………………….


…………………………………..

……………………………………………….



mysql_connect("localhost","root","");

mysql_select_db("school");

……………………………….

…………………………………..

……………………………………………….




?>

As you see in above example that there is no chance of visible of the database details. That means it is secure. Thus connections are made easy in Php.

As you see in the above example the database name is clearly visible. That means there is chance for “hackers” for malfunctioning of the database. So today many programmers don’t follow this method. When come to the second one here the details of database connection are kept in some dbconnection.php and that dbconnection.php is include in eachpage.php where database connection is necessary and the basic syntax for that is as follows:-

<?
……………………………….
…………………………………..
……………………………………………….
include "dbconnection.php";
………………………………………………
…………………………………………….

?>
As you see in above example that there is no chance of visible of the database details. That means it is secure. Thus connections are made easy in Php.
The minor towers next to the citizen.



This post first appeared on Php Source Codes, please read the originial post: here

Share the post

How to connect a database in Php

×

Subscribe to Php Source Codes

Get updates delivered right to your inbox!

Thank you for your subscription

×