I'm using stdClass
to create a class and I'd like to add all column data to it automatically. Currently, I'm doing the following from within a function...
function get_course_info($course_id){
$course = new stdClass;
//Add everything from the courses table to the "$course" class
$query = $db->query("SELECT * FROM courses WHERE course_id = ?",array($course_id));
$results = $query->first();
$course->type = $results->type;
$course->category = $results->category;
$course->name = $results->name;
etc.......
This is working fine, but if I someday add a new column to the courses table (let's say "description"), I'd like that info. to automatically be added to my stdClass
without having to go back and manually add it in as a new line in this function.
Is there a way to do this?