s.mujtaba Posted January 2, 2009 Share Posted January 2, 2009 Hi everyone I want to a config.php file to make connection with database but when make it, It's like this: <?php mysql_connect( /*dbhost*/ "localhost", /*dbuser*/ "root", /*dbpass*/ "" ); mysql_select_db( /*dbname*/ "data" ); ?> But I don't want it like that, I want it like this: <?php $dbhost = "localhost"; $dbuser = "root"; $dbpass = ""; $dbname = "data"; ?> Please help me to make it professional.. Link to comment https://forums.phpfreaks.com/topic/139182-solved-how-do-i-make-a-professional-configphp-file/ Share on other sites More sharing options...
s.mujtaba Posted January 2, 2009 Author Share Posted January 2, 2009 up up please help me fast :'( Link to comment https://forums.phpfreaks.com/topic/139182-solved-how-do-i-make-a-professional-configphp-file/#findComment-727957 Share on other sites More sharing options...
Mchl Posted January 2, 2009 Share Posted January 2, 2009 please help me fast :'( It certainly was not professional of you How about this <?php $config = array( "dbhost" => "localhost", "dbuser" => "root", "dbpass" => "", "dbname" => "data" ); ?> And then you use it in your other files using require For example <?php require_once("config.php"); mysql_connect( $config["dbhost"], $config["dbuser"], $config["dbpass"] ); mysql_select_db( $config["dbname"] ); ?> Link to comment https://forums.phpfreaks.com/topic/139182-solved-how-do-i-make-a-professional-configphp-file/#findComment-727958 Share on other sites More sharing options...
s.mujtaba Posted January 2, 2009 Author Share Posted January 2, 2009 Hi No I don't want that I want this like other scripts <?php $dbhost = "localhost"; $dbuser = "root"; $dbpass = ""; $dbname = "data"; ?> Any one help me please Link to comment https://forums.phpfreaks.com/topic/139182-solved-how-do-i-make-a-professional-configphp-file/#findComment-727960 Share on other sites More sharing options...
Mchl Posted January 2, 2009 Share Posted January 2, 2009 My... and just how difficult would that be? <?php $dbhost = "localhost"; $dbuser = "root"; $dbpass = ""; $dbname = "data"; ?> <?php require_once("config.php"); mysql_connect( $dbhost, $dbuser, $dbpass ); mysql_select_db( $dbname ); ?> Link to comment https://forums.phpfreaks.com/topic/139182-solved-how-do-i-make-a-professional-configphp-file/#findComment-727961 Share on other sites More sharing options...
s.mujtaba Posted January 2, 2009 Author Share Posted January 2, 2009 Thanks man, that what I want Link to comment https://forums.phpfreaks.com/topic/139182-solved-how-do-i-make-a-professional-configphp-file/#findComment-727963 Share on other sites More sharing options...
Mchl Posted January 2, 2009 Share Posted January 2, 2009 Just keep in mind, that storing all config data in a single array (like I showed you in the first example) will make your life easier. Link to comment https://forums.phpfreaks.com/topic/139182-solved-how-do-i-make-a-professional-configphp-file/#findComment-727964 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.