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