jaxdevil Posted December 12, 2007 Share Posted December 12, 2007 Hi guys, Its been a bit since i had to ask a question, I have increased the size and dynamics of my program now exponentially, the problem is I inserted the sql connection data (i.e. I copied the data below) on EVERY page, so instead of one single conifg file I have the sql connection settings on each page. I am trying to make it able to switch between databases on the fly and its impossible since the program now has some 87 inter-connected php scripts that connect to the database and it would be best to be able to change the database selected for all of them with one file, instead of opening 87 pages in notepad and changing the db_name on each. Here is my mysql connection data, what I need to do is make it accessible to each page with some function like... <?php include(config.inc.php); ?> The only problem is these are also in seperate directories, and the config file would be located in the root public web directory. So how would I format that? i.e. http://www.whatever.com/config.inc.php or /config.inc.php or home/wherever/public_html/config.inc.php etc. Here is my code... <?php $db_host = "localhost"; $db_user = "xxxxx"; $db_pwd = "xxxxxx"; $db_name = "xxxxx"; mysql_connect($db_host, $db_user, $db_pwd); mysql_select_db($db_name); ?> Thanks in advance guys. SK Quote Link to comment Share on other sites More sharing options...
everisk Posted December 12, 2007 Share Posted December 12, 2007 Try include("../config.inc.php"); Quote Link to comment Share on other sites More sharing options...
revraz Posted December 12, 2007 Share Posted December 12, 2007 In your include statement, you can either use relative paths to point to the config file or use a absolute path using a starting point from your web root. Quote Link to comment Share on other sites More sharing options...
jaxdevil Posted December 12, 2007 Author Share Posted December 12, 2007 Thanks guys. I tried those, it does not connect to the database. Here is what I have in the actual config file... <?php $db_host = "localhost"; $db_user = "xxxxxx"; $db_pwd = "xxxxxx"; $db_name = "xxxxxx"; mysql_connect($db_host, $db_user, $db_pwd); mysql_select_db($db_name); ?> and here is what I have the include statement as... <?php include("../config.inc.api.php"); ?> Now if I replace the include statement with the sql connect data it connects, but when I switch it to the include data it does not connect. I can not figure out what I am doing wrong. These files are in multiple levels also (i.e. the one I am testing on is in public_html/api/old) but I tried using my absolute path to the config.inc.php file in the public_html directory and the unix (../config.inc.api.php) root setting. I have no idea where I am going wrong. Thanks again, SK Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted December 12, 2007 Share Posted December 12, 2007 To form an absolute file system path at runtime, use - require($_SERVER[''DOCUMENT_ROOT''] . "/your_path/yourfile.php"); Also, if you require the code and data in the file for your program to work, you should use require() instead of include(). Checking your web server log for error will help you troubleshoot why it is not working. Quote Link to comment Share on other sites More sharing options...
jaxdevil Posted December 12, 2007 Author Share Posted December 12, 2007 AH HAH! I figured it out, you guys were right, you figured it out actuallyl, i just figured out what happened. I had moved servers a few weeks back and the path changed, I got it now Thanks a million guys! SK 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.