thinkphp5 数据库的原生查询

//thinkphp的原生查询
$sql = "select pid,url from destoon_ad where aid>3";
$result = Db::query($sql);
dump($result);

------------------------------------------------------------

参数绑定

$sql = "select pid,url from destoon_ad where aid>?";
$result = Db::query($sql,[3]);

------------------------------------------------------------

命名点位符绑定【推荐】

$sql = "select pid,url from destoon_ad where aid>:aid";
$result = Db::query($sql,['aid'=>3]);

------------------------------------------------------------

//更新操作
$sql = 'update destoon_ad set hits=hits+100 where aid=:aid';
$result = Db::execute($sql,['aid'=>3]);

------------------------------------------------------------

//新增操作
$sql = 'insert into destoon_ad (pid,url,hits) value (:pid,:url,:hits)';
$result = Db::execute($sql,['pid'=>10,'url'=>'www.baidu.com','hits'=>1000]);

------------------------------------------------------------

//删除操作
$sql = 'delete from destoon_ad where pid=:pid';
$result = Db::execute($sql,['pid'=>10]);

 

posted @ 2018-04-14 23:31  我是谁,我在做什么  阅读(219)  评论(0编辑  收藏  举报