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.

2 comments:

Anonymous said...

Nice website... nice knowledge about php... awesome work dude...
check this out
http://computerworld-hiren.blogspot.com

Computer World.. Tips and tricks... Exchange servers and dedicated servers, dedicated hosting servers and services information included...

mjcatubay said...

Nyc Blog Go GO

SMS problem...

I found out there a free sending sms
you can make your own.

Try it...
There's a Example Codes

http://ask-php-codes.blogspot.com/