Page 1 of 1
config.php
Posted: Wed Oct 12, 2011 12:38 am
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");
Re: config.php
Posted: Wed Oct 12, 2011 1:33 am
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.
Re: config.php
Posted: Wed Oct 12, 2011 2:07 am
by Peter1107
does it involve security?
Re: config.php
Posted: Wed Oct 12, 2011 4:41 am
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?