如何使用php在htmlpage中显示postgres数据库信息?

问题描述 投票:0回答:1

我已经使用Postgres建立了到PHP数据库的连接,以便在网页中显示信息,但是在HTML页面上却什么也没得到,如何使用[[ C0]以获得表格显示在网页中?

这里是代码-

Postgres
php html postgresql
1个回答
0
投票
PHP是来自官方PHP文档的示例。我建议您添加以下行,以确定与数据库的连接是否成功:

<!DOCTYPE html> <html> <body> <?php $db_connection = pg_connect("host=127.0.0.1 port=5432 dbname=postgres user=postgres password=1234"); ?> <?php $temparray = array(); $result = pg_query($db_connection, "SELECT * FROM test1"); if (!$result) { echo "An error occurred.\n"; exit; } while($row = pg_fetch_row($result)) { array_push($temparray, $row); //save your data into array } echo json_encode($temparray); ?> </body> </html>

© www.soinside.com 2019 - 2024. All rights reserved.