fluvius Posted October 29, 2008 Share Posted October 29, 2008 Hi all, I'll admit that I'm certainly no PHP expert, hardly even a novice, and I'm sure that will be evidenced by this problem I'm experiencing. We're currently moving a client from one host to another, but it's presenting an error when trying to access the MySQL database on the new host. Here's the error, followed by the contents of the config.php file: Warning: main(/var/www/html/_common/cls-database-inc.php) [function.main]: failed to open stream: No such file or directory in /home/sites/rccdams.co.uk/public_html/_common/config.php on line 26 Warning: main(/var/www/html/_common/cls-database-inc.php) [function.main]: failed to open stream: No such file or directory in /home/sites/rccdams.co.uk/public_html/_common/config.php on line 26 Fatal error: main() [function.require]: Failed opening required '/var/www/html/_common/cls-database-inc.php' (include_path='.:/usr/share/pear') in /home/sites/rccdams.co.uk/public_html/_common/config.php on line 26 <? $root = $HTTP_SERVER_VARS['DOCUMENT_ROOT']; if ($root == "C:/apachefriends/xampp/htdocs") { $db_host = "localhost"; $db_username = "root"; $db_password = "password"; $db_database = "database"; } else { $db_host = "localhost"; $db_username = "username"; $db_password = "password"; $db_database = "database"; } require ($root . "/_common/cls-database-inc.php"); <-- This is line 26 require ($root . "/_common/site-functions-inc.php"); $db = new database; $db->setdataconnection($db_host,$db_username,$db_password,$db_database); ?> Can anyone offer any advice for what may be wrong? If you need any further info just let me know. Best regards, Tony. [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/130626-problem-connecting-to-database/ Share on other sites More sharing options...
Mchl Posted October 29, 2008 Share Posted October 29, 2008 Is there a file called 'cls-database-inc.php' in '/var/www/html/_common/' ? Because this Warning says just this: Can't open this file. Quote Link to comment https://forums.phpfreaks.com/topic/130626-problem-connecting-to-database/#findComment-677733 Share on other sites More sharing options...
fluvius Posted October 29, 2008 Author Share Posted October 29, 2008 Is there a file called 'cls-database-inc.php' in '/var/www/html/_common/' ? Because this Warning says just this: Can't open this file. Hi, Yes, both the cls-database-inc.php and site-functions-inc.php files exist in the _common folder. One thought has occured me to after posting this. To keep the existing site live until the new one is working, a domain reference has been set up with the new host so the all the site files could be loaded to it and visited via a browser. Could this error be caused because it's trying to reference the cls-database-inc.php file using the full URL and failing because this refers to the existing site, not the new one? Hope that makes sense. Thanks for your help. Tony. Quote Link to comment https://forums.phpfreaks.com/topic/130626-problem-connecting-to-database/#findComment-677744 Share on other sites More sharing options...
IndyTechNerd Posted October 29, 2008 Share Posted October 29, 2008 change this... $root = $HTTP_SERVER_VARS['DOCUMENT_ROOT']; to this... $root = $_SERVER['DOCUMENT_ROOT']; $HTTP_SERVER_VARS didn't work, but $_SERVER did. I think the former is outdated. change this... require ($root . "/_common/cls-database-inc.php"); require ($root . "/_common/site-functions-inc.php"); to this... require ($root . "_common/cls-database-inc.php"); require ($root . "_common/site-functions-inc.php"); Give that a shot. What I did was use a test page I have and instead of require($root...), I just echoed it. What I got was "<!---C:/wamp/www//_common/cls-database-inc.php -->" see the //, looks like $root has the "/" at the end of the directory. Quote Link to comment https://forums.phpfreaks.com/topic/130626-problem-connecting-to-database/#findComment-677761 Share on other sites More sharing options...
Mchl Posted October 29, 2008 Share Posted October 29, 2008 In fact realpath() could be used to get rid of any OS dependent differences. Quote Link to comment https://forums.phpfreaks.com/topic/130626-problem-connecting-to-database/#findComment-677783 Share on other sites More sharing options...
fluvius Posted October 29, 2008 Author Share Posted October 29, 2008 Thanks IndyTechNerd. I tried your code changes but sadly with no improvement. Any other thoughts? Quote Link to comment https://forums.phpfreaks.com/topic/130626-problem-connecting-to-database/#findComment-677806 Share on other sites More sharing options...
IndyTechNerd Posted October 29, 2008 Share Posted October 29, 2008 try doing an echo of $root to see what directory is being pulled. You show 2 in your error message... Warning: main(/var/www/html/_common/cls-database-inc.php) [function.main]: failed to open stream: No such file or directory in /home/sites/rccdams.co.uk/public_html/_common/config.php on line 26 Quote Link to comment https://forums.phpfreaks.com/topic/130626-problem-connecting-to-database/#findComment-677820 Share on other sites More sharing options...
Mchl Posted October 29, 2008 Share Posted October 29, 2008 My bet is: your new system has different paths than the old one (seems like the new one is Windows, while the include paths are linuxish). Quote Link to comment https://forums.phpfreaks.com/topic/130626-problem-connecting-to-database/#findComment-677828 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.