I've two files in one directory named (classes )which contain classes, first one for main class (Database ) which build to connect to the database. And the second one (Branch ) extends Database class which made to get data from the database.
When I try to run "getBranch" function I got an error says :
Uncaught Error: Class 'Database' not found in C:\xampp\htdocs\branches\classes\branch.php
Please find the codes below and advise what's required.
database.php:
<?php
class Database {
private $host;
private $user;
private $pwd;
private $dbName;
public $conn;
public function connect() {
$this->host = "localhost";
$this->user = "root";
$this->pwd = "";
$this->dbName = "branchs";
//create connection
$conn = new mysqli($this->host, $this->user, $this->pwd, $this->dbName);
//chech connection
if ($conn->connect_error) {
die("Connection failed :" . $conn->connect_error);
} else {
echo "Success";
}
return $conn;
}
}
?>
branch.php :
<?php
class Branch extends Database {
public function getBranch() {
$sql = "SELECT * FROM branches";
$result = $this->connect()->query($sql);
if ($result->num_rows > 0) {
while ($row = $result->fetch_assoc()) {
echo "Name :" . $row['brName'] . "City :" . $row['brCity'] . "<br>";
}
} else {
echo "0 results";
}
}
}
?>