品易云推流 关闭
文章详情页
文章 > PostgreSQL > php如何连接postgresql

php如何连接postgresql

头像

yang

2020-04-11 15:13:294370浏览 · 0收藏 · 0评论

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

关注

关注公众号,随时随地在线学习

本教程部分素材来源于网络,版权问题联系站长!

底部广告图