Reputation: 63
The direction structure the following
Source folder
Pages
Style
When I trying to include the DBLink.php class to the CalendarClass.php, I get the following error messages:
Warning: include(../Database/DBLink.php): failed to open stream: No such file or directory in D:\apache\htdocs\Engine\Classes\CalendarClass.php on line 3
Warning: include(): Failed opening '../Database/DBLink.php' for inclusion (include_path='D:\apache\php\PEAR') in D:\apache\htdocs\Engine\Classes\CalendarClass.php on line 3
Fatal error: Class 'DBLink' not found in D:\apache\htdocs\Engine\Classes\CalendarClass.php on line 10
The content of the CalendarClass.php:
<?php
include "../Database/DBLink.php";
class CalendarClass{
private $link;
function __construct() {
$this->link = new DBLink();
}
function UpdateCalendar(){
$this->link->ClearCalendar();
}
}
?>
What is the right way to include the DbLink.php to the CalendarClass.php ?
Upvotes: 0
Views: 49
Reputation: 63
Solution: Change the include to include __DIR__ . "/../Database/DBLink.php"
Upvotes: 0
Reputation: 4766
You need to use
__DIR__ . "/../Database/DBLink.php";
PHP is looking for this file, but starts at a different root path
.
You need to provide a full path so that PHP will look up the correct path.
__DIR__
provides the path to the directoy the file lies in.
An easier way would be to use autoloading
Upvotes: 2