config.php

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Peter1107
Forum Newbie
Posts: 2
Joined: Tue Oct 11, 2011 10:35 am

config.php

Post by Peter1107 »

why do we need to make separated php file for database connection?

Code: Select all

$dbHost='localhost';
$dbUser='root';
$dbPass='';
$dbName='test';
$dbC=mysql_connect($dbHost, $dbUser, $dbPass, $dbName) or die("unable to connect");
jraede
Forum Contributor
Posts: 254
Joined: Tue Feb 16, 2010 5:39 pm

Re: config.php

Post by jraede »

You don't, it's just good practice so you can include it wherever you need it instead of copying/pasting everything and then having to go back and change every single instance if you need to change one piece of information.
Peter1107
Forum Newbie
Posts: 2
Joined: Tue Oct 11, 2011 10:35 am

Re: config.php

Post by Peter1107 »

does it involve security?
jraede
Forum Contributor
Posts: 254
Joined: Tue Feb 16, 2010 5:39 pm

Re: config.php

Post by jraede »

Not at all. Just think about it...say you have a bunch of different access points (pages) and you want them all to be able to connect to the database, what's easier? Having all that mysql_connect() stuff on each page, or just including the connect file? If you just include the file, then any change you have to make will only have to be made on that one file, as opposed to on each file that uses the mysql_ functions to connect to the database.

Make sense?
Post Reply