There is an index.php file, which lies in the root, it connects a file with a connection to the database, so that it can be seen in this file:
require_once(ROOT.'/components/Db.php'); Here is the file Db.php:
class Db { public static function getConnection() { $paramsPath = ROOT . '/config/db_params.php'; $params = include($paramsPath); $dsn = "mysql:host={$params['host']};dbname={$params['dbname']};charset=UTF8"; $db = new PDO($dsn, $params['user'], $params['password']); return $db; } } There is a file (lorem.php) that makes requests to the database, it has a connection to the database:
$db = Db::getConnection(); And when I'm already in another file (ipsum.php) I include lorem.php, with:
require_once("/lorem.php"); Then the problem arises in it, it gives an error: Fatal ERROR: Class 'Db' not found in D: \ wamp \ www \ models \ lorem.php Although if you track the transmission chain of the class Db: Db.php -> index.php - > lorem.php -x-> ipsum.php then everything should be fine. Tell me, what's the problem?