问题描述:

Thanks for reading. How does one make the class name dynamic in a FETCH_CLASS query. i.e. so that this method can be called by any class...(what do you replace 'User' with)

 public static function find_by_sql($sql){

global $handler;

$query = $handler->query($sql);

$object_array = $query->fetchAll(PDO::FETCH_CLASS, 'User');

return $object_array;

}

Solution (embarrassingly) is....

 public static function find_by_sql($sql){

global $handler;

$query = $handler->query($sql);

$class = get_class($this);

$object_array = $query->fetchAll(PDO::FETCH_CLASS, $class);

return $object_array;

}

相关阅读:
Top