感谢阅读。如何在FETCH_CLASS查询中使类名动态化。即所以任何一个班级都可以调用这种方法......(你用什么取代'用户')
public static function find_by_sql($sql){
global $handler;
$query = $handler->query($sql);
$object_array = $query->fetchAll(PDO::FETCH_CLASS, 'User');
return $object_array;
}
解决方案(令人尴尬)是......
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;
}