php postgresql 连接 查询,php如何连接postgresql

php如何连接postgresql

9c6fad1a9c1c78361f86ca3a305b602e.png

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教程

php如何连接postgresql相关教程

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值