laravel的一些查询语句

刚开始使用这个框架还是有一些不一样的地方

比如我之前想把那个sql语句写到查询里面。文档里面的写法是

然后再百度上面找到的写法是可以写到select里面

$sql="SELECT a.uid,
substring_index( substring_index( a.data1, ',', b.help_topic_id + 1 ), ',',- 1 ) phone
FROM 表名 a JOIN mysql.help_topic b ON b.help_topic_id < ( length( a.data1 ) - length( REPLACE ( a.data1, ',', '' ) ) + 1 )
WHERE a.data1 IS NOT NULL and a.data1!=''";
$data = DB::select($sql);
另外就是在新增的时候
insertGetId是插入一条数据可以进行使用。多条数据使用
DB::table('users')->insert([
    ['email' => 'taylor@example.com', 'votes' => 0],
    ['email' => 'dayle@example.com', 'votes' => 0]
]);
 
posted @ 2018-10-18 11:23  做网站的菜鸟  阅读(174)  评论(0编辑  收藏  举报