首页 > 解决方案 > 如何在浏览器中列出 postgresql 表数据?

问题描述

环境:

问题: 在 shell 提示符中回显 Postgresql 表数据,但在浏览器中没有。

php代码:

$src="<html>\n<head>,\n<title>db test</title>\n</head>\n<body>\n<table>";
$dbc=pg_connect("host=localhost dbname=cricket user=cao password=cri123");
$dmq="select * from batsmen";
$result=pg_query($dbc, $dmq);
while($row=pg_fetch_assoc($result)){
$src.="\n<tr><td>".$row['id']."</td><td>".$row['name']."</td></tr>";
}
pg_clear_result($result);
pg_close($dbc);
src.="\n</table>\n</body>\n</html>";

例如,shell 提示中的页面源代码:

<html>
<head><title>db test</title></head>
<body>
<table>
<tr><td>1</td><td>Broad man</td></tr>
<tr><td>2</td><td>Richards</td></tr>
<tr><td>3</td><td>Sachin</td></tr>
<tr><td>4</td><td>Lara</td></tr>
</table>
</body>
</html>

但是,浏览器中的页面源代码:

<html>
<head><title>db test</title></head>
<body>
<table>
</table>
</body>
</html>

IE。只发送静态代码,但不发送动态表数据到浏览器。

标签: phppostgresqlapache

解决方案


程序:
s1: yum install php httpd
s2: yum install postgresql-server postgresql-contrib
s3: yum install php-pgsql
s4: service postgresql initdb
systemctl start postgresql
systemctl enable postgresql
service postgresql restart
s5: edit pg_hba.conf
...
host all所有 127.0.0.1/32 ident
主机 所有 所有 ::1/128 ident
...

...
主机 所有 127.0.0.1/32 md5
主机 所有 所有 ::1/128 md5
...
s6:service postgresql restart
s7:setsebool -P httpd_can_network_connect_db 1


推荐阅读