SQL表不会出现在页面上

时间:2016-06-16 22:13:53

标签: php mysql

我在html页面上显示我的表时遇到一些问题。这是代码:

$resultaten = $conn->prepare("SELECT * FROM GastenBoek ORDER BY ID DESC");
$resultaten->execute();
while($rij = $resultaten->fetch(PDO::FETCH_ASSOC))
{
    $ID = $row['ID']; //Hier zeg ik : haal ID uit Row.
    $Email = $row['Email'];
    $Bericht  = $row['Bericht'];
    $Tijd = $row['Tijd'];
    $Datum = $row['Datum'];
    echo $Email;
}

我尝试过使用PDOStatement,但根本没有解决它。 提前谢谢。

1 个答案:

答案 0 :(得分:0)

你会试试吗

$conn = new \PDO('mysql:host='. DB_HOST .';dbname='. DB_NAME, DB_USER, DB_PASSWORD);

$conn->exec("SET NAMES utf8");
$conn->exec("SET character_set_connection = utf8");
$conn->exec("SET character_set_client = utf8");
$conn->exec("SET character_set_results = utf8");

$resultaten = $conn->prepare("SELECT * FROM GastenBoek ORDER BY ID DESC");
$resultaten->execute();
$result = $resultaten->fetchAll(\PDO::FETCH_ASSOC);
foreach($result as $value)
{
    $ID = $value['ID']; //Hier zeg ik : haal ID uit Row.
    $Email = $value['Email'];
    $Bericht  = $value['Bericht'];
    $Tijd = $value['Tijd'];
    $Datum = $value['Datum'];
    echo $Email;
}