php - 如何在浏览器中列出 postgresql 表数据?
问题描述
环境:
- centos6
- php-5.3
- php-pgsql-5.3
- php-pdo-5.3
- httpd-2.2
- postgres-8.4
问题: 在 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。只发送静态代码,但不发送动态表数据到浏览器。
解决方案
程序:
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
推荐阅读
- wordpress - 在woocommerce表单内的下拉列表中显示所有产品
- ios - “无法检索产品信息”“无效的产品标识符”SwiftyStoreKit iOS Swift Xcode
- db2 - 连接到 LDAP 服务器时出现 IBM DB2 Warehouse Developer Edition Web 控制台错误
- mariadb - 了解 mariadb 死锁
- javascript - 如何从 API 获取和显示特定 JSON 数据的正确方法
- c# - 无法使用 Zabbix Rest API 更新或删除 Zabbix 触发器
- google-sheets - 如何在 Excel 或 Google 表格中创建指向晨星股票价值的链接?
- swift - 从选取器中选择该图像后,UIImageView 未更新新图像。甚至没有在 didFinishPickingMediaWithInfo 上打印信息
- php - laravel 项目的 CI/CD 如何使其稳定
- awk - 我的 linux 命令是“ps -C opmn | awk 'NR >4 {print $4}'”