入门客AI创业平台(我带你入门,你带我飞行)
博文笔记

MySQL 返回影响行数的测试示例

创建时间:2012-03-17 投稿人: 浏览次数:2166

(在测试MySQL 5.1.36上测试)

found_rows() : select
row_count() : update delete insert

注:需要配合相应的操作一起使用,否则返回的值只是1和-1(都是不正确的值)

示例:
 
drop database if exists `mytest`;
create database `mytest`;
use `mytest`;

drop table if exists `MyTestTable`;
create table `MyTestTable`(`ID` int ,`Name` varchar(10));

insert into `MyTestTable`(`ID`,`Name`)
select "1","role1" union all
select "2","role2" union all
select "3","role3";
select row_count(); -- 输出3(返回新添加的记录数),[注:如果使用insert into...values只返回1]

select * from `MyTestTable`;select found_rows(); -- 输出3(返回选择的行数)
update `MyTestTable` set `Name`="people";select row_count(); -- 输出3(返回修改的行数)
delete from `MyTestTable`;select row_count(); -- 输出3(返回删除的行数)

声明:该文观点仅代表作者本人,入门客AI创业平台信息发布平台仅提供信息存储空间服务,如有疑问请联系rumenke@qq.com。
  • 上一篇:没有了
  • 下一篇:没有了
未上传头像