当前位置:首页 > PHP教程 > PHP总结归纳

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

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

  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(返回删除的行数)


【说明】本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:)!