note 79179 added to function.pg-affected-rows
| From: | Anonymous at osu1 dot php dot net | Date: | Wed, 14 Nov 2007 15:45:17 +0000 |
| Subject: | note 79179 added to function.pg-affected-rows | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-132274@lists.php.net to get a copy of this message | ||
pg-affected-rows () only runs on the LAST SQL STATEMENT executed. If you compound several
statements together then pg_affected_rows might not return what you expect.
For example:
<?php
$result = pg_query ('BEGIN; INSERT INTO foo (bar) VALUES (\'baz\'; COMMIT');
echo (pg_affected_rows ($result));
?>
will cause 0 to be printed, because the last statement executed by Postgres was COMMIT, which
doesn't affect any rows.
I haven't tried this so am not certain it works, but you SHOULD be able to get the row counts
you want if you split your queries up.
For example:
<?php
$result = pg_query ('BEGIN; INSERT INTO foo (bar) VALUES (\'baz\';');
echo (pg_affected_rows ($result));
pg_query ('COMMIT;');
?>
should allow you to get the number of rows affected by the previous query. I haven't tried
this yet though, so don't count on it.
----
Server IP: 69.147.83.197
Probable Submitter: 82.108.107.33
----
Manual Page -- http://www.php.net/manual/en/function.pg-affected-rows.php
Edit -- https://master.php.net/note/edit/79179
Del: integrated -- https://master.php.net/note/delete/79179/integrated
Del: useless -- https://master.php.net/note/delete/79179/useless
Del: bad code -- https://master.php.net/note/delete/79179/bad+code
Del: spam -- https://master.php.net/note/delete/79179/spam
Del: non-english -- https://master.php.net/note/delete/79179/non-english
Del: in docs -- https://master.php.net/note/delete/79179/in+docs
Del: other reasons-- https://master.php.net/note/delete/79179
Reject -- https://master.php.net/note/reject/79179
Search -- https://master.php.net/manage/user-notes.php