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

yii2之原生sql

时间:2017-07-12 17:51:34      阅读:208      评论:0      收藏:0      [点我收藏+]

标签:nec   use   com   time   select   employee   pre   connect   logs   

只是两个使用例子,从别处摘来的,留着后面参考:

方式一:

1 $connection  = Yii::$app->db;
2 $sql     = "select * from hd_article where aid<".$aid." order by aid desc limit 1";
3 $command = $connection->createCommand($sql);
4 $res     = $command->queryAll($sql);

 

方式二:

1  $query = new \yii\db\Query();
2  $query->select(‘pa_call.id,pa_call.tableid,pa_call.time as msgtime,pa_table_area.id as areaid,pa_table_area.areaname as area,pa_table.tablename,pa_call.message as msg,pa_call.new as needoper,pa_call.status as isdone,pa_employee.username as oper‘)
3             ->from(Call::tableName())
4             ->join(‘LEFT JOIN‘,Table::tableName(),‘pa_call.tableid=pa_table.id‘)
5             ->join(‘LEFT JOIN‘,Area::tableName(),‘pa_table_area.id=pa_table.areaid‘)
6             ->join(‘LEFT JOIN‘,Employee::tableName(),‘pa_call.employeeid=pa_employee.id‘)
7             ->where($where);
8         $command = $query->createCommand();
9         $data = $command->queryAll();

 

yii2之原生sql

标签:nec   use   com   time   select   employee   pre   connect   logs   

原文地址:http://www.cnblogs.com/yunyunde/p/7156454.html

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