码迷,mamicode.com
首页 > 数据库 > 详细

thinkphp5 数据库的原生查询

时间:2018-04-15 11:38:59      阅读:1269      评论:0      收藏:0      [点我收藏+]

标签:set   命名   url   delete   int   nbsp   pid   http   推荐   

//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]);

技术分享图片

 

thinkphp5 数据库的原生查询

标签:set   命名   url   delete   int   nbsp   pid   http   推荐   

原文地址:https://www.cnblogs.com/my2018/p/8836717.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!