欢迎各位兄弟 发布技术文章
这里的技术是共享的
4月23日,武汉源创会火热报名中,期待您的参与>>>>>
//模型文件app/models/Archives.php
class
Archives
extends
Eloquent{
protected
$table
=
'archives'
;
public
$timestamps
= false;
}
//路由文件
Route::get(
'/test'
,
array
(
'as'
=>
'routetest'
function
(){
//DB类位于 vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php
//$arr = DB::select('select * from archives where id=?',[1]);//查
//$arr = DB::insert('insert into archives (title,body)values(?,?)',array('title2','body2'));//增
//$arr = DB::update('update archives set title=?,body=? where id=?',array('new1','newbody1',4));//改
//$arr = DB::delete('delete from archives where id=?',array(4));//删
//$arr = DB::table('archives')->where('id','>',1)->orderBy('id','desc')->get();//获取多条数据
//$arr = DB::table('archives')->orderBy('id','desc')->first();//获取第一条数据
//$arr = DB::table('archives')->where('id',2)->pluck('title');//获取一条数据的指定字段
//$arr = DB::table('archives')->where('id','>',1)->lists('title');//获取一张表的一列字段
//$arr = DB::table('archives')->join('arctype','arctype.id','=','archives.typeid')->select('archives.*','arctype.typename')->get();//JOIN试例
//$arr = DB::table('archives')->where('id','>',1)->toSql();//获取查询的SQL语句,公用于条件,不能用于get()之类的有结果之中
//模型查询,模型类的父类Eloquent 位于/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php
$arr
= Archives::find(3);
//查询id为3的一条数据
= Archives::all(
'id'
'title'
));
//查询全部数据
= Archives::where(
'typeid'
'='
,1)->orderBy(
'desc'
)->get();
}));