php连接postgresql
来源:互联网 发布:淘宝会员抓取系统下载 编辑:程序博客网 时间:2024/06/05 21:02
http://php.net/manual/en/book.pgsql.php
首先推荐一下postgres数据库,免费,强大,甚至某些方面比商业数据库还要好,大家可以试试。
测试代码:
<?php$conn_string = "host=localhost port=5432 dbname=db_name user=yourname password=yourpassword" ; $dbconn = pg_connect($conn_string);if (!$dbconn) echo "连接失败!!!!!/r/n";else echo "连接成功!!!!!/r/n"; pg_close($dbconn);?>
user一般为安装期间新建的用户postgres
例
<?php
// 连接,选择数据库
$dbconn = pg_connect("host=localhost dbname=publishing user=postgres password=foo port=5432")
or die( 'Could not connect: ' . pg_last_error());
// 执行 SQL 查询
$query = 'SELECT * FROM authors';
$result = pg_query($query) or die('Query failed: ' . pg_last_error());
// 用 HTML 显示结果
echo "<table>\n";
while ($line = pg_fetch_array($result, null, PGSQL_ASSOC)) {
echo "\t<tr>\n";
foreach ( $line as $col_value) {
echo "\t\t<td>$col_value</td>\n";
}
echo "\t</tr>\n";
}
echo "</table>\n";
// 释放结果集
pg_free_result($result);
// 关闭连接
pg_close($dbconn);
?>
// 连接,选择数据库
$dbconn = pg_connect("host=localhost dbname=publishing user=postgres password=foo port=5432")
// 执行 SQL 查询
$query = 'SELECT * FROM authors';
$result = pg_query($query) or die('Query failed: ' . pg_last_error());
// 用 HTML 显示结果
echo "<table>\n";
while ($line = pg_fetch_array($result, null, PGSQL_ASSOC)) {
}
echo "</table>\n";
// 释放结果集
pg_free_result($result);
// 关闭连接
pg_close($dbconn);
?>
目录
- pg_affected_rows — 返回受影响的记录数目
- pg_cancel_query — 取消异步查询
- pg_client_encoding — 取得客户端编码方式
- pg_close — 关闭一个 PostgreSQL 连接
- pg_connect — 打开一个 PostgreSQL 连接
- pg_connection_busy — 获知连接是否为忙
- pg_connection_reset — 重置连接(再次连接)
- pg_connection_status — 获得连接状态
- pg_convert — 将关联的数组值转换为适合 SQL 语句的格式。
- pg_copy_from — 根据数组将记录插入表中
- pg_copy_to — 将一个表拷贝到数组中
- pg_dbname — 获得数据库名
- pg_delete — 删除记录
- 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 array
- pg_fetch_all — 从结果中提取所有行作为一个数组
- pg_fetch_array — 提取一行作为数组
- pg_fetch_assoc — 提取一行作为关联数组
- pg_fetch_object — 提取一行作为对象
- pg_fetch_result — 从结果资源中返回值
- pg_fetch_row — 提取一行作为枚举数组
- pg_field_is_null — 测试字段是否为 NULL
- pg_field_name — 返回字段的名字
- pg_field_num — 返回字段的编号
- pg_field_prtlen — 返回打印出来的长度
- pg_field_size — 返回指定字段占用内部存储空间的大小
- pg_field_table — Returns the name or oid of the tables field
- pg_field_type_oid — Returns the type ID (OID) for the corresponding field number
- pg_field_type — 返回相应字段的类型名称
- pg_free_result — 释放查询结果占用的内存
- pg_get_notify — Ping 数据库连接
- pg_get_pid — Ping 数据库连接
- pg_get_result — 取得异步查询结果
- pg_host — 返回和某连接关联的主机名
- pg_insert — 将数组插入到表中
- pg_last_error — 得到某连接的最后一条错误信息
- pg_last_notice — 返回 PostgreSQL 服务器最新一条公告信息
- pg_last_oid — 返回上一个对象的 oid
- pg_lo_close — 关闭一个大型对象
- pg_lo_create — 新建一个大型对象
- pg_lo_export — 将大型对象导出到文件
- pg_lo_import — 将文件导入为大型对象
- pg_lo_open — 打开一个大型对象
- pg_lo_read_all — 读入整个大型对象并直接发送给浏览器
- pg_lo_read — 从大型对象中读入数据
- pg_lo_seek — 移动大型对象中的指针
- pg_lo_tell — 返回大型对象的当前指针位置
- pg_lo_unlink — 删除一个大型对象
- pg_lo_write — 向大型对象写入数据
- pg_meta_data — 获得表的元数据
- pg_num_fields — 返回字段的数目
- pg_num_rows — 返回行的数目
- 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_query — 执行查询
- pg_result_error_field — Returns an individual field of an error report.
- pg_result_error — 获得查询结果的错误信息
- pg_result_seek — 在结果资源中设定内部行偏移量
- pg_result_status — 获得查询结果的状态
- pg_select — 选择记录
- 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_send_query — 发送异步查询
- pg_set_client_encoding — 设定客户端编码
- pg_set_error_verbosity — Determines the verbosity of messages returned by pg_last_error() andpg_result_error().
- pg_trace — 启动一个 PostgreSQL 连接的追踪功能
0 0
- PHP连接PostgreSQL
- php 连接 postgreSql
- php连接postgresql
- PostgreSQL连接PHP
- PHP 连接PostgreSql数据库代码
- PHP-2-使用-测试PHP连接PostgreSQL
- php与MySQL、PostgreSQL的连接设置
- PHP连接不上PostgreSQL的问题
- php使用PDO扩展连接PostgreSQL对象关系数据库
- php连接PostgreSQL错误Call to undefined function pg_connect()
- windows & linux (centOS/ubuntu) 下 PostgreSQL安装 python php 连接 PostgreSQL
- PostgreSQL的相关连接
- VC代码连接PostgreSql
- VB6连接PostgreSQL数据库
- Postgresql 客户端连接问题
- Perl 连接Postgresql
- 远程连接postgreSQL数据库
- postgresql pgadmin 连接服务器
- HDU 1429 状压bfs 胜利大逃亡
- Java Observable 模式
- 八皇后问题(DFS剪枝)
- 数据结构——快速排序
- 【android】解决华为手机无法输出Log.d(..)的问题
- php连接postgresql
- android.view.ViewRoot$CalledFromWrongThreadException 异常的解决方案Activity类runOnUiThread方法
- java中利用正则表达式过滤特殊字符
- 【deeplearning】【框架】【caffe】之 caffe安装
- 【Linux】启动mongo db后台服务
- C++/C宏定义中## 连接符与# 符的含义
- 链表实现栈
- C# 使用SqlBulkCopy类批量复制大数据
- 代码笔记 | 一个简单的游戏框架