Código PHP:
class myClass
{
public function db_connect()
{
try {
$dbh = new PDO('mysql:host=localhost;dbname=agenda','root', 'protego');
foreach($dbh->query('SELECT id from agenda') as $row) {
print_r($row);
}
$dbh = null;
}catch (PDOException $e) {
print "Error!: " . $e->getMessage() . "<br/>";
die();
}
}
}
$perl = new myClass();
$perl->db_connect();