note 79180 added to function.pg-affected-rows

From: Date: Wed, 14 Nov 2007 15:46:24 +0000
Subject: note 79180 added to function.pg-affected-rows
Groups: php.notes 
Request: Send a blank email to php-notes+get-132275@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/79180 Del: integrated -- https://master.php.net/note/delete/79180/integrated Del: useless -- https://master.php.net/note/delete/79180/useless Del: bad code -- https://master.php.net/note/delete/79180/bad+code Del: spam -- https://master.php.net/note/delete/79180/spam Del: non-english -- https://master.php.net/note/delete/79180/non-english Del: in docs -- https://master.php.net/note/delete/79180/in+docs Del: other reasons-- https://master.php.net/note/delete/79180 Reject -- https://master.php.net/note/reject/79180 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#132275) next »