This is a database class which connects to the database taking in the host name, username, password and the databasename. The MembersModel class after the DatabaseConnect class, which also extends the DatabaseConnect, is supposed to retrieve information.
<?php class DatabaseConnect { protected $conn; protected $host, $username, $password, $database; public function __construct($host, $username, $password, $database){ // Create connection $this->conn = new mysqli($host, $username, $password,$database) OR die("There was a problem connecting to the database"); return true; } public function query($sql) { $result = $this->conn->query($sql); if (!$result) { die('Invalid query:'); } return $result; } public function __destruct(){ $this->conn->close() OR die("Problem disconnecting from the database"); } } class MemberModel extends DatabaseConnect { public function getAllMembers() { $result = $this->query("SELECT * FROM members"); return $result; } } To connect and retrieve from the database this is what I have been trying to do
$db = new DatabaseConnect("localhost", "root", "", "pcaframework"); $allMembers = $db->getAllMembers(); while ($row = mysqli_fetch_assoc($allMembers)) { echo "First Name: " . $row['name'] ."<br />"; echo "Last Name: " . $row['email'] ."<br />"; echo "<hr />"; } but this is what I get "Fatal error: Call to undefined method DatabaseConnect::getAllMembers()". Can you point out the problem here.