I'll try to use fetch_object('Classname') to test this method.
The Class Inserent in Inserent.php:
namespace classes\model;
class Inserent{
private $nummer;
private $nickname;
private $email;
public function __construct ($nummer, $nickname, $email){
$this->nummer = $nummer;
$this->nickname = $nickname;
$this->email = $email;
}
public function getNummer(){
return $this->nummer;
}
public function setNummer($nummer){
$this->nummer = $nummer;
}
...
}
The use is in a Mapper-Class InserentDAO.php:
namespace classes\mapper;
use classes\model\Inserent;
class InserentDAO{
private $dbConnect;
public function __construct (){
$this->dbConnect = MySQLDatabase::getInstance();
}
public function readAll(){
$sql = "SELECT inserentennummer, nickname, email FROM inserent";
$inserent = null;
$inserentList = array();
if ($result = $this->dbConnect->query($sql)) {
while ($inserent = $result->fetch_object('classes\model\Inserent')) {
$inserentList[] = $inserent;
}
$result->close();
}
return $inserentList;
}
...
}
I get errors and my Objects are empty:
Warning: Missing argument 1 for classes\model\Inserent::__construct() in D:\xampp\htdocs\workspace\secondStep\classes\model\Inserent.php on line 10
Warning: Missing argument 2 for classes\model\Inserent::__construct() in D:\xampp\htdocs\workspace\secondStep\classes\model\Inserent.php on line 10
Warning: Missing argument 3 for classes\model\Inserent::__construct() in D:\xampp\htdocs\workspace\secondStep\classes\model\Inserent.php on line 10
Notice: Undefined variable: nummer in D:\xampp\htdocs\workspace\secondStep\classes\model\Inserent.php on line 11
Notice: Undefined variable: nickname in D:\xampp\htdocs\workspace\secondStep\classes\model\Inserent.php on line 12
Notice: Undefined variable: email in D:\xampp\htdocs\workspace\secondStep\classes\model\Inserent.php on line 13
But if I change the code, in the Mapper, it will works.
part of the code InserentDAO.php instead:
while ($obj = $result->fetch_object()) {
$inserent = new Inserent($obj->inserentennummer, $obj->nickname, $obj->email);
$inserentList[] = $inserent;
}