本文介绍了计算从上次SQL查询插入的行数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这个查询:
INSERT INTO db1.outbox (DestinationNumber, TextDecoded) SELECT User.CellPhone, '$SMSMessage' as TextDecoded FROM db2.User WHERE User.PurchaseDate BETWEEN 2012-01-01 AND 2012-01-31它向发件箱"表中插入了多行.但我不知道插入了多少行.如何从该SQL语法插入行数?谢谢.
it does multiple rows insertion to 'outbox' table. but I don't know how many rows inserted. how to have number of rows inserted from that SQL syntax? thanks.
更新 由于此命令,我得到了"-1":
update I got '-1' as result of this command :
$insertedRows = mysql_query("SELECT ROW_COUNT()"); $rowInserted = mysql_fetch_array($insertedRows); $rowInserted = $rowInserted[0]; echo $rowInserted;但是我看到桌上插入了27行.我做错了什么?
but I see there are 27 rows inserted on my table. what did I do wrong?
推荐答案将此放在您的最后一条语句中;
put this on your last statement;
SELECT ROW_COUNT();更新1
如何使用 mysql_affected_rows ,例如
<?php $link = mysql_connect('localhost', 'mysql_user', 'mysql_password'); if (!$link) { die('Could not connect: ' . mysql_error()); } mysql_select_db('mydb'); /* this should return the correct numbers of deleted records */ mysql_query('you SQL QUERY HERE'); printf("Records deleted: %d\n", mysql_affected_rows()); ?>更多推荐
计算从上次SQL查询插入的行数
发布评论