php 记录数,PHP 返回受影响的记录数目

用户评论:

Anonymous (2007-12-20 03:02:55)

There is something called auto-commit, when you supply more than one query delimited by ; semicolon all-or-none is done if one fails. No need for BEGIN;COMMIT;ROLLBACK when doing one query. its logic to mee pg_affected_rows() returns affected rows and if you want to do 2 queries apart from each other.. do a BEGIN and then 1 and get pg_affected_rows() then do 2 and get pg_affected_rows() and then finally do COMMIT;

Anonymous (2007-11-14 07:45:17)

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:

$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:

$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.

(2005-08-05 03:31:34)

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.

(2005-06-29 06:15:31)

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 (2005-06-28 01:45:06)

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值