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.. Quote Link to comment 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 :'( Quote Link to comment 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"] ); ?> Quote Link to comment 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 Quote Link to comment 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 ); ?> Quote Link to comment 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 Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.