mysql postgresql php_[转]php连接postgresql

首先推荐一下postgres数据库,免费,强大,甚至某些方面比商业数据库还要好,大家可以试试。

安装:

补充一点:最后Stack Builder提示下载的东西,如果网速不好,或者有事,可以不下载,不影响使用。

PHP连接:

php.ini中将extension=php_pgsql.dll前面的分号去掉,然后设置extension_dir指向php文件下的ext文件夹。

或者直接把将./php/libpq.dll(php文件夹下的libpq.dll)和./php/ext/php_pgsql.dll(ext文件夹下的php_pgsql.dll)这两个dll文件复制到C盘system32下。

正常情况下这样php就可以连接postgres了,但是我的仍然出错,提示“Fatal error: Call to undefined function pg_connect()”,查看Apache的日志,“PHP Startup: Unable to load dynamic library '****\\PHP5\\ext\\php_pdo_pgsql.dll”。

经过查找,在Apache中conf文件夹下的配置文件httpd.conf中添加 LoadFile "***/PHP5/libpq.dll",位置在LoadModule后面即可。

(***为php安装路径)

测试代码:

echo "连接成功!!!!!/r/n";

pg_close($dbconn);?>

user一般为安装期间新建的用户postgres

例1767.PostgreSQL 例子<?php //连接,选择数据库

$dbconn = pg_connect("host=localhost dbname=publishing user=postgres password=foo port=5432")

ordie('Could not connect: ' .pg_last_error());//执行 SQL 查询

$query = 'SELECT * FROM authors';$result = pg_query($query) or die('Query failed: ' .pg_last_error());//用 HTML 显示结果

echo "

$col_value

}echo "\t

\n";

}echo "

\n";//释放结果集

pg_free_result($result);//关闭连接

pg_close($dbconn);?>

目录

pg_close — 关闭一个 PostgreSQL 连接pg_connect — 打开一个 PostgreSQL 连接pg_convert — 将关联的数组值转换为适合 SQL 语句的格式。pg_copy_from — 根据数组将记录插入表中pg_copy_to — 将一个表拷贝到数组中pg_end_copy — 与 PostgreSQL 后端同步pg_escape_bytea — 转义 bytea 类型的二进制数据pg_escape_string — 转义 text/char 类型的字符串pg_execute — Sends a request to execute a prepared statement with given parameters, and waits for the result.pg_fetch_all_columns — Fetches all rows in a particular result column as an arraypg_fetch_all — 从结果中提取所有行作为一个数组pg_fetch_row — 提取一行作为枚举数组pg_field_size — 返回指定字段占用内部存储空间的大小pg_field_table — Returns the name or oid of the tables fieldpg_field_type_oid — Returns the type ID (OID) for the corresponding field numberpg_field_type — 返回相应字段的类型名称pg_get_pid — Ping 数据库连接pg_host — 返回和某连接关联的主机名pg_insert — 将数组插入到表中pg_last_error — 得到某连接的最后一条错误信息pg_last_notice — 返回 PostgreSQL 服务器最新一条公告信息pg_last_oid — 返回上一个对象的 oidpg_lo_export — 将大型对象导出到文件pg_lo_import — 将文件导入为大型对象pg_lo_open — 打开一个大型对象pg_lo_read_all — 读入整个大型对象并直接发送给浏览器pg_lo_read — 从大型对象中读入数据pg_lo_seek — 移动大型对象中的指针pg_lo_tell — 返回大型对象的当前指针位置pg_lo_write — 向大型对象写入数据pg_options — 获得和连接有关的选项pg_parameter_status — Looks up a current parameter setting of the server.pg_pconnect — 打开一个持久的 PostgreSQL 连接pg_ping — Ping 数据库连接pg_port — 返回该连接的端口号pg_prepare — Submits a request to create a prepared statement with the given parameters, and waits for completion.pg_put_line — 向 PostgreSQL 后端发送以 NULL 结尾的字符串pg_query_params — Submits a command to the server and waits for the result, with the ability to pass parameters separately from the SQL command text.pg_result_error_field — Returns an individual field of an error report.pg_result_seek — 在结果资源中设定内部行偏移量pg_send_execute — Sends a request to execute a prepared statement with given parameters, without waiting for the result(s).pg_send_prepare — Sends a request to create a prepared statement with the given parameters, without waiting for completion.pg_send_query_params — Submits a command and separate parameters to the server without waiting for the result(s).pg_set_error_verbosity — Determines the verbosity of messages returned by pg_last_error() andpg_result_error().pg_trace — 启动一个 PostgreSQL 连接的追踪功能

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值