Jump to content

Recommended Posts

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]

Link to comment
https://forums.phpfreaks.com/topic/130626-problem-connecting-to-database/
Share on other sites

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.

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.

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.