<?php
class Test
{
private $id;
private $name;
public function getId()
{
return $this->id;
}
public function getName()
{
return $this->name;
}
}
$pdo = new PDO('mysql:dbname=myDb;host=db.budgies.de');
$statement = $pdo->query('SELECT id, name FROM test LIMIT 3');
$result = $statement->fetchAll(PDO::FETCH_CLASS, Test::CLASS);
foreach ($result as $test) {
echo $test->getId() . ' = ' . $test->getName() . PHP_EOL;
}