>  기사  >  백엔드 개발  >  ThinkPHP中的CURD操作,ThinkPHPCURD操作_PHP教程

ThinkPHP中的CURD操作,ThinkPHPCURD操作_PHP教程

WBOY
WBOY원래의
2016-07-13 09:54:20974검색

ThinkPHP中的CURD操作,ThinkPHPCURD操作

<?<span>php
    </span><span>//</span><span>查询多条记录,返回二维数组</span>
    <span>$result</span> = M("admin")-><span>select();
    </span><span>$result</span> = M("admin")->where("id>2")-><span>select();
    </span><span>$result</span> = M("admin")->where("id>2")->order("id desc")->limit("0,5")->field("id,username,psssword")-><span>select();
    </span><span>$result</span> = M("admin")->where("id>2")->group("messageId")->having("messageId > 3")->order("id desc")->limit("0,5")->field("id,username,psssword")-><span>select();
    </span><span>//</span><span>查询一条记录,返回一维数组</span>
    <span>$result</span> = M("admin")-><span>find();
    </span><span>$result</span> = M("admin")->where("id=2")-><span>find();

    </span><span>//</span><span>要处理的数据放在数组data中</span>
    <span>$data</span>   = <span>array</span><span>(
            </span>"username" => 'wang',
            "password" => "123456"<span>
        );
    </span><span>//</span><span>添加记录,返回影响行数</span>
    <span>$updateRowNum</span> = M("admin")->add(<span>$data</span><span>);
    </span><span>//</span><span>删除记录,返回影响行数</span>
    <span>$updateRowNum</span> = M("admin")->where("id = 2")-><span>delete();
    </span><span>//</span><span>修改数据放在新数组new_data中</span>
    <span>$new_data</span>   = <span>array</span><span>(
            </span>"username" => 'wang_new',
            "password" => "123456_new"<span>
        );
    </span><span>//</span><span>修改记录,返回影响行数</span>
    <span>$updateRowNum</span> = M("admin")->where("id = 2")->save(<span>$new_data</span><span>);
    
    </span><span>//</span><span>执行select语句(不管是多行还是一行,全部返回二维数组)</span>
    <span>$result</span> = M()->query("select * from admin a,user u where a.id = user.aid"<span>);
    </span><span>//</span><span>执行insert、update、delete语句,返回受影响行数</span>
    <span>$updateRowNum</span> = M()->execute("insert/update/delete语句"<span>);
    </span><span>//</span><span>计算查询行数(一般用于select语句)</span>
    <span>$row</span>    = M("admin")->select()-><span>count</span><span>();
    </span><span>$row</span>    = M("admin")->where("id > 3")->select()-><span>count</span><span>();
</span>?>

 

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/998220.htmlTechArticleThinkPHP中的CURD操作,ThinkPHPCURD操作 ? php // 查询多条记录,返回二维数组 $result = M("admin")- select(); $result = M("admin")-where("id2")- select(); $result =...
성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.