Re: Security with dbHost, dbUser, dbPassword
| From: | Satyam | Date: | Wed, 10 Jan 2007 22:59:05 +0000 |
| Subject: | Re: Security with dbHost, dbUser, dbPassword | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-246863@lists.php.net to get a copy of this message | ||
----- Original Message ----- From: "Otto Wyss" <otto.wyss@orpatec.ch>
What is the usual save way to store/use DB access info in a script. I currently just use some PHP variables in a file which I include in all other scripts. config.php <?PHP if (!defined ("config_include")) die ("Error..."); $dbhost = "localhost"; $dbuser = "name"; $dbpass = "password"; $dbname = "database"; $dbcoll = "utf8_unicode_ci"; ?> Is this save enough or are there better ways? Where should I store this file so it isn't accessible via the net but inside scripts? O. WyssBesides what Jochem has already sugested, I would add that I usually have in the include file, in an unaccessible path as he said, a function that returns a connection. The function has all the connection information local, so that they are neither global variables nor constants, just local literal values within the function. In the same function I put the call to mysql_select_db. Though I check the return values for errors, I usually ignore them since unless you have either more than one database engine or more than one database, the default link resource does not need to me explicitly passed to other functions. Satyam