我正在尝试用 PDO 中没有运气的数据库中的数据填充表。我是 PHP 新手,所以我四处搜索,但尚未找到解决方案。该表根本没有填充,没有数据。这是我的代码。
$stmt = $dbh->prepare("SELECT * FROM actividades");
$stmt->execute();
echo "<table id=\"premiacionguaynabo\"> <tr> <th> No. </th> <th> Fecha </th> <th> Torneo </th> <th> Lugar </th> <th> Organizador </th> <th> Opciones </th> </tr>"; //The table and the headers are created
$tno = 0;
$result = $stmt->fetchall(PDO::FETCH_ASSOC);
foreach($result as $line) {
$tno = $tno + 1;
$id = $line["idactividades"];
print "<tr class=\"alt2\">";
print "<td id=\"idtorneo\"> $tno </td>";
print "<td class=\"fechatorneo\"> " . $line['fecha_inicial'] . " al " . $line['fecha_final'] . "</td>";
print "<td> <a id=\"plinks\" href=\"$picture\" rel=\"lightbox\" target=\"_top\" title=\"Flyer del Torneo\"> " . $line['ntorneo'] . " </a></td>";
print "<td>" . $line['ltorneo'] . "</td>";
print "<td>" . $line['otorneo'] . "</td>";
print "<td id=\"idtorneo\"> <a id=\"udlinks\" href=\"uactividades.php?idactividades=$id\"> Edit </a> <a id=\"udlinks\" onclick=\"return confirmDelete()\" href=\"dactividades.php?idactividades=$id\"> Delete </a></td>";
print "</tr>";
}
print "</table>";
这是我连接到我的数据库的方式
$dbhost = 'myhost';
$dbname = 'dbname';
$dbuser = 'myuser';
$dbpass = 'mypass';
try {
$dbh = new PDO("mysql:host=$dbhost;dbname=$dbname;", $dbuser, $dbpass);
}
catch(PDOException $e)
{
echo $e->getMessage();
}