Load mysqli_fetch_object directly into class
I'm currenyly looking into classes, etc. I'd like to load something into
my object from my database, like this:
$result = mysqli_query($link,"SELECT * FROM `recepten` WHERE `id` =
$id LIMIT 1");
$obj = mysqli_fetch_object($result);
$this->id = $obj->id;
$this->titel = $obj->titel;
$this->ingredient = $obj->ingredient;
$this->beschrijving = $obj->beschrijving;
$this->van = $obj->van;
$this->tot = $obj->tot;
$this->altijd = $obj->altijd;
As you can see I'm loading $obj directly into $this. I'm guessing there
must be a faster way to do this, I simply can't figure out how... Also
google doesn't help.
Any thoughts?
No comments:
Post a Comment