I've created a class named Database.
class Database extends mysqli {
public function __construct() {
parent::__construct();
$mysqli = new mysqli(DBHOST, DBUSER, DBPASSWORD, DBDATABASE);
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
}
}
And a class called Model that extends Database
class Model {
function __construct() {
$this->db = new Database();
}
}
And a class registerModel that extends Model
class registerModel extends Model {
public function __construct() {
echo "This is the register Model";
}
public function register(//VARIOUS PASSED VALUES) {
**$stmt = $mysqli->prepare("INSERT INTO users (firstName, lastName) values (?, ?)");**
...
... More Code
...
}
What I'm trying to do is get the $mysqli from the original Database class, but I'm unsure how to refer to it. I've tried everything, but nothing seems to work.
P.S. The first two classes are always required in my application, and the last registerModel class is called via a controller. Which is why I don't construct the parent in the sub-classes.
new()inside the constructor, pass them as an argument from the outside instead.