note 79180 deleted from function.pg-affected-rows by ezyang

From: Date: Wed, 14 Nov 2007 20:14:08 +0000
Subject: note 79180 deleted from function.pg-affected-rows by ezyang
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-132281@lists.php.net to get a copy of this message
Note Submitter: Anonymous Reason: useless ---- 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.

« previous php.notes (#132281) next »