php如何连接postgresql
2023-04-18 14:24:38 时间
PHP中可以使用pg_connect函数连接postgresql数据库。
pg_connect() 打开一个由 connection_string 所指定的 PostgreSQL 数据库的连接。如果成功则返回连接资源,如果不能连接则返回 FALSE。connection_string 应该是用引号引起来的字符串。
语法:
pg_connect ( string $connection_string ) : resource
pg_connect() 返回其它 PostgreSQL 函数所需要的资源。
pg_connect() 打开一个由 connection_string 所指定的 PostgreSQL 数据库的连接。如果成功则返回连接资源,如果不能连接则返回 FALSE。connection_string 应该是用引号引起来的字符串。
示例:
<?php $dbconn = pg_connect("dbname=mary"); //connect to a database named "mary" $dbconn2 = pg_connect("host=localhost port=5432 dbname=mary"); // connect to a database named "mary" on "localhost" at port "5432" $dbconn3 = pg_connect("host=sheep port=5432 dbname=mary user=lamb password=foo"); //connect to a database named "mary" on the host "sheep" with a username and password $conn_string = "host=sheep port=5432 dbname=test user=lamb password=bar"; $dbconn4 = pg_connect($conn_string); //connect to a database named "test" on the host "sheep" with a username and password ?>
推荐:PostgreSQL教程
相关文章
- 一文读懂边缘计算与云计算!
- 使用Loki收集网络设备日志
- 亚马逊云科技推出Amazon SimSpace Weaver助力大规模空间模拟
- 为什么要避免使用公共WiFi
- WiFi 6 带来的不仅是高速
- 了解边缘计算及其对当今企业的重要性!
- Socket到底是什么?你想知道吗?
- 亚马逊云科技推出安全数据湖Amazon Security Lake
- 医疗保健和边缘——未来的合作伙伴关系
- 五分钟内了解 OSI 模型
- 2023年值得关注的六大IT趋势
- 数字经济时代,火山引擎助力企业云上增长
- 欧盟计划将数据中心送入太空,云计算真的要上天了?
- 想构建自己的蜂窝模块吗?这是需要做的
- SaaS蔓延:含义、危害、现状及缓解方案
- 零信任网络中如何保护自己的隐私?不经意随机访问机简介
- 建设智慧城市:云存储的重要性
- Wasm气候已成!
- 5G和边缘计算如何使仓库自动化受益?
- 未来的6G网络将如何应对移动数据的需求?