TashaAT Posted July 9, 2008 Share Posted July 9, 2008 I have an application that needs me to go and put the DB settings manually. Can I do this? Write a config file like this: define('DB_SERVER', ''); define('DB_SERVER_USERNAME', ''); define('DB_SERVER_PASSWORD', ''); define('DB_DATABASE', ''); define('USE_PCONNECT', 'false'); define('STORE_SESSIONS', ''); Put the information in and on every page put this: require('configure.php'); And is there an easier / better way to do it? Link to comment https://forums.phpfreaks.com/topic/113927-config-file/ Share on other sites More sharing options...
alco19357 Posted July 9, 2008 Share Posted July 9, 2008 yes or to save constants you can do an array $databaseInfo = array( "host" => "localhost", "user" => "myuser", "pass" => "password", "db" => "database", "pconn" => false, "store_sess" => "" ); Then add an include 'config.php'; to each page and just use this where needed $databaseInfo["host"], etc. Link to comment https://forums.phpfreaks.com/topic/113927-config-file/#findComment-585520 Share on other sites More sharing options...
cooldude832 Posted July 9, 2008 Share Posted July 9, 2008 Constants are designed for things that don't change so I don't see how that is wasting constants. Or is it somehow wasting them cause I do exactly that I have tons of constants usually so if I change table names/dbs etc everything always syncs. Link to comment https://forums.phpfreaks.com/topic/113927-config-file/#findComment-585522 Share on other sites More sharing options...
alco19357 Posted July 14, 2008 Share Posted July 14, 2008 You can use either one. It really doesn't matter. I guess maybe I just like to keep stuff in a organized coherent fashion, aligning alike terms together. However, you can use either a constant or an array. Link to comment https://forums.phpfreaks.com/topic/113927-config-file/#findComment-589897 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.