Reputation: 2654
In Codeigniter, how can i fetch the result set from DB query into a model? In native PHP PDO engine i have something like:
$pdo->setFetchMode(PDO::FETCH_INTO, new className());
So i have a class:
class ClassName {
private $id;
}
What i want is the result from db query to populate the class, so:
$query = $this->db->get_where("table", array("id" => 1));
$object = $query->row.....(new className());
echo $object->id;
// Shows 1
Thanks Radu
Upvotes: 2
Views: 363
Reputation: 15044
If I understand you correctly, this is what you are trying to do.
Per the documentation:
$query = $this->db->get_where('table', array('id' => 1));
$object = $query->row(0, 'Your_Class_name') // Class MUST be loaded prior to use
echo $object->id; // Shows 1
Upvotes: 1