pg_affected_rows

(PHP 4 >= 4.2.0, PHP 5, PHP 7, PHP 8)

pg_affected_rows返回受影响的记录数(元组)

说明

pg_affected_rows(PgSql\Result $result): int

pg_affected_rows() 返回受 INSERTUPDATEDELETE 查询影响的元组数(实例/记录/行)。

从 PostgreSQL 9.0 及更高版本开始,服务器返回 SELECT 的行数。较旧的 PostgreSQL 则返回 0。

注意:

此函数过去称为 pg_cmdtuples()

参数

result

PgSql\Result 实例,由 pg_query()pg_query_params() 或者 pg_execute()(等)返回。

返回值

受查询影响的行数。如果没有元组受到影响,它将返回 0

更新日志

版本 说明
8.1.0 现在 result 参数接受 PgSql\Result 实例,之前接受 资源(resource)

范例

示例 #1 pg_affected_rows() 示例

<?php
$result
= pg_query($conn, "INSERT INTO authors VALUES ('Orwell', 2002, 'Animal Farm')");

$cmdtuples = pg_affected_rows($result);

echo
$cmdtuples . " tuples are affected.\n";
?>

以上例程会输出:

1 tuples are affected.

参见

  • pg_query() - 执行查询
  • 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_execute() - Sends a request to execute a prepared statement with given parameters, and waits for the result
  • pg_num_rows() - 返回行的数目

add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top