ThinkPHP中的CURD操作,ThinkPHPCURD操作_PHP教程
程序员文章站
2022-05-20 11:54:33
...
ThinkPHP中的CURD操作,ThinkPHPCURD操作
php //查询多条记录,返回二维数组 $result = M("admin")->select(); $result = M("admin")->where("id>2")->select(); $result = M("admin")->where("id>2")->order("id desc")->limit("0,5")->field("id,username,psssword")->select(); $result = M("admin")->where("id>2")->group("messageId")->having("messageId > 3")->order("id desc")->limit("0,5")->field("id,username,psssword")->select(); //查询一条记录,返回一维数组 $result = M("admin")->find(); $result = M("admin")->where("id=2")->find(); //要处理的数据放在数组data中 $data = array( "username" => 'wang', "password" => "123456" ); //添加记录,返回影响行数 $updateRowNum = M("admin")->add($data); //删除记录,返回影响行数 $updateRowNum = M("admin")->where("id = 2")->delete(); //修改数据放在新数组new_data中 $new_data = array( "username" => 'wang_new', "password" => "123456_new" ); //修改记录,返回影响行数 $updateRowNum = M("admin")->where("id = 2")->save($new_data); //执行select语句(不管是多行还是一行,全部返回二维数组) $result = M()->query("select * from admin a,user u where a.id = user.aid"); //执行insert、update、delete语句,返回受影响行数 $updateRowNum = M()->execute("insert/update/delete语句"); //计算查询行数(一般用于select语句) $row = M("admin")->select()->count(); $row = M("admin")->where("id > 3")->select()->count(); ?>