public function getObjects(string $sql, array $data = [], $class = 'stdClass')
{
return $this->query($sql, $data)->fetchAll(PDO::PDO::FETCH_CLASS, $class);
}
public function query(string $sql, array $data = [])
{
$sth = $this->dbh->prepare($sql);
$sth->execute($data);
return $sth;
}
public function query(string $sql, array $data = [], $class)
{
$sth = $this->dbh->prepare($sql);
$sth->execute($data);
$dbArray = $sth->fetchAll();
$ret = [];
foreach ($dbArray as $row){
$item = new $class;
foreach ($row as $key => $value){
if (is_numeric($key)){
continue;
}
$item->$key = $value;
}
$ret[] = $item;
}
return $ret;
}