- This topic is empty.
Viewing 3 posts - 1 through 3 (of 3 total)
Viewing 3 posts - 1 through 3 (of 3 total)
- The forum ‘Back End’ is closed to new topics and replies.
The forums ran from 2008-2020 and are now closed and viewable here as an archive.
Is it possible to use mysqli inside another class? I’ve already initialized it outside the class. Here is the class (User)
<?php
/*
* User Class
* Provides information about the user in an OOP fashion
* Trying to be very swish here
*/
Class User{
// User info variables
public $id;
public $email;
public $password;
public $forename;
public $surname;
function __constructor(){
if(isset($_SESSION)){
$this->getUserInfo($_SESSION);
}
}
function getUserInfo($id){
$stmt = $Database->prepare(“SELECT * FROM users WHERE id = ?”);
$stmt->bind_param(“s”, $id);
$stmt->execute();
$stmt->bind_result($id, $email, $password, $forname, $surname);
while($stmt->fetch()){
$this->id = $id;
$this->email = $email;
$this->password = $password;
$this->forename = $forename;
$this->surname = $surname;
}
}
}
However the variables are empty and using the **getUserInfo();** It says that $Database is undefined, despite being declared outside and before the User class.
The variable is still undefined even using the global keyword.
That’s worked, thanks buddy.