计算从上次SQL查询插入的行数

编程入门 行业动态 更新时间:2024-10-24 20:20:55
本文介绍了计算从上次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查询插入的行数

本文发布于:2023-10-24 09:36:13,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1523592.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:行数   SQL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!