Deprecated: The each() function is deprecated. This message will be suppressed on further calls in /home/zhenxiangba/zhenxiangba.com/public_html/phproxy-improved-master/index.php on line 456
PHP: pg_affected_rows - Manual
[go: Go Back, main page]

PHP
downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

pg_cancel_query" width="11" height="7"/> <PostgreSQL 関数
Last updated: Mon, 05 Feb 2007

view this page in

pg_affected_rows

(PHP 4 >= 4.2.0, PHP 5)

pg_affected_rows — 変更されたレコード(タプル)の数を返す

説明

int pg_affected_rows ( resource result )

pg_affected_rows() は、INSERT, UPDATE, DELETE クエリにより変更されたタプル(インスタンス/レコード/行)の数を 返します。

注意: この関数は、以前は pg_cmdtuples() と呼ばれていました。

パラメータ

result

pg_query(), pg_query_params() あるいは pg_execute() から返される PostgreSQL の クエリ結果リソース。

返り値

クエリによって変更された行の数を返します。もし変更されたタプルがない場合は 0 を返します。

例 1763. pg_affected_rows() の例

<?php
$result
= pg_query($conn, "INSERT INTO authors VALUES ('オーウェル', 2002, '動物農場')");

$cmdtuples = pg_affected_rows($result);

echo
$cmdtuples . " タプルが変更されました。\n";
?>

上の例の出力は以下となります。


1 タプルが変更されました。

    

参考

pg_query()
pg_query_params()
pg_execute()
pg_num_rows()



add a note add a note User Contributed Notes
pg_affected_rows
05-Aug-2005 07:31
That's not quite true, I've been able to execute multiple queries in a single call just fine. In stead, it has to do with the fact this function returns the affected rows for the last executed query, not the last set of queries specified to a single call to pg_query.
29-Jun-2005 10:15
Concering Bruno Baguette's note:

The pg_query function only allows one query per function call.  When you do your
$sql="BEGIN;
INSERT ...
COMMIT;";
$result=pg_query($conn,$sql);
echo pg_affected_rows($result);

you get a zero, because only the BEGIN; is executed.

The single query per call is, I beleive, a PHP builtin protection against SQL injection attacks.  (Ie someone submitting a string paramter that ends the current query and appends another one)
Bruno Baguette
28-Jun-2005 05:45
Note that when you submit several SQL queries, within one BEGIN;COMMIT; like this one :

$SQLQuery = 'BEGIN;';
$SQLQuery.= 'INSERT INTO a (a,b) VALUES (1,2);';
$SQLQuery.= 'INSERT INTO b (ref_b,c) VALUES (2,5);';
$SQLQuery.= 'COMMIT;';

$HandleResults = pg_query($SQLQuery);
echo(pg_affected_rows($HandleResults));

pg_affected_rows() will return 0

 
show source | credits | sitemap | contact | advertising | mirror sites