Mac_ThinkPHP_增删改查语句(原生sql语句)

1.Select 查询语句 占位方式一

        //sql 查询语句 占位方式一
        $sql = "select * from tp_articles where id =?";
        $result =  Db::query($sql,[104]);
        dump($result);

  Select 查询语句 占位方式二

        //sql 查询语句 占位方式二
        $sql = "select * from tp_articles where id =:id";
        $result =  Db::query($sql,["id" => 103]);
        dump($result);

2.insert 插入语句

        //插入语句
        $sql = "insert into tp_articles(title,desn,body) values(:title,:desn,:body)";
        $result = Db::execute($sql,['title' => '我是标题111', 'desn' => '我是描述','body'=>'aaaaaa']);
        dump($result);

3.修改语句

        //修改语句
        $sql = "update tp_articles set title=:title where id=:id";
        $ret = Db::execute($sql,["title" => "我是队长啊威啊","id" => 220]);
        dump($ret);

4.删除语句

        //删除语句
        $sql = "delete from tp_articles where id=:id";
        $ret = Db::execute($sql,["id" => 220]);
        dump($ret);

 


 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章