我正在尝试在HTML表中显示数据库中的数据。主要问题是:该表未出现。<html><head><body> <table> <tr> <th>Id</th> <th>String</th> <th>Array</th> </tr> <?php// Mostrar dadosecho "<table>";{$databaseName = 'visteon';$pdo = new Pdo('mysql:host=127.0.0.1;dbname=' . $databaseName, 'root', '');$result = $pdo->query('SHOW TABLES FROM ' . $databaseName)->fetchAll(PDO::FETCH_NUM);$Tabela = [];foreach ($result as $r) {$Tabela[] = $r[0];}$data = [];foreach ($Tabela as $Tabela) {$data[$Tabela] = $pdo->query('SELECT * FROM ' . $Tabela)->fetchAll(PDO::FETCH_ASSOC);}echo "</table>";var_dump($Tabela);var_dump($data);}?></table></body></html>
2 回答
MM们
TA贡献1886条经验 获得超2个赞
使用try-catch在你的代码是这样的:
try {
$pdo = new Pdo('mysql:host=127.0.0.1;dbname=$databaseName .', 'root',
array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
$result = $pdo->query('SHOW TABLES FROM ' . $databaseName)->fetchAll(PDO::FETCH_NUM);
} catch (PDOException $e) {
throw new Exception("Error with PDO: " . $e->getMessage());
}
并更正您的代码(检查我的第二行)。
- 2 回答
- 0 关注
- 390 浏览
添加回答
举报
0/150
提交
取消