I'm trying to make a object of a class from another file. Both file is located in the same folder & I used 'namespace App' in the both files. In the login files I'm trying to get the class object but it couldn't find the class. Codes are given below.
Database Class : 'Database.php'
<?php
namespace App;
require_once 'config.php';
class Database{
private $db;
public function __construct(){
$this->db = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
}
public function getConnection(){
return $this->db;
}
login.php file :
<?php
namespace App;
use App\Database;
require_once 'config.php';
$DB = new Database();
$con = $DB->getConnection;
When I execute login.php , it says Fatal error: Uncaught Error: Class 'App\Database' not found in login.php on line 10
use Database;if you're in the same\Appnamespace as the class you're using.