<?php
$username='miguelde_modulo4';
$password='modulo4';
$dbname='miguelde_modulo4';
$host='localhost';
echo'
<html>
<h3> Site Rafael e Lorenzo - Listagem de Leituras </h3>
<table border = 2>
<tr>
<td>IdLeitura</td>
<td>Placa Mac</td>
<td>Nome da Placa</td>
<td>Data Leitura</td>
<td>Hora Leitura</td>
<td>Valor</td>
</tr>
';
try {
 $conn = new PDO("mysql:host=$host;dbname=$dbname", $username, $password);
 $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
 $sql='SELECT leitura.idleitura,
 leitura.mac_idmac,
 mac.nome,
 leitura.dataleitura,
 leitura.horaleitura,
 leitura.valor
 from leitura, mac
 where leitura.mac_idmac=mac.idmac
 ';
 $data = $conn->query($sql);
 foreach($data as $row) {
 echo'<td>'.($row[0]).'</td>';
 echo'<td>'.($row[1]).'</td>';
 echo'<td>'.($row[2]).'</td>';
 echo'<td>'.($row[3]).'</td>';
 echo'<td>'.($row[4]).'</td>';
 echo'<td>'.($row[5]).'</td><tr>';
 }echo'</table>';
} catch(PDOException $e) {
 echo 'ERROR: ' . $e->getMessage();
}
 ?>