Public Function Demo ()
{
$res = null;
Insert Data Insertion
$user =array (' username ' = ' joy ', ' password ' = ' 123456 ', ' age ' =>23);
$res = db::table (' users ')->insert ($user);
/*
Data query
$res = db::table (' users ')->where (' username ', ' joy ')->get ();
$res = Db::select (' select * from users WHERE username= ' joy ');
*/
/*
Update data
$res =db::update (' Update users SET age=25 WHERE username= ' joy ');
$res =db::table (' users ')->where (' username ', ' joy ')->update (Array (' age ' =>23));
*/
/*
Delete data
$res = DB::d elete (' Delete from users WHERE username= ' joy ');
$res = db::table (' users ')->where (' username ', ' joy ')->delete ();
*/
/*
Field Additions
$res = Db::statement (' ALTER TABLE ' users ADD sex tinyint (1) NOT null default 0 ');
*/
/* Transaction
Db::transaction (function () {
$user =array (xxxx);
Db::table (' user ')->insert ($user);
Db.....
});
*/
/* Result Finder
$res = db::table (' users ')->where (' username ', ' Qing ')->pluck (' age ');//Go to a specific field value
$res = db::table (' users ')->lists (' age ');//Special Field list value
$res = db::table (' users ')->select (array (' ID ', ' username ')->get (); Multiple special field queries
$res = db::table (' users ')->where (' id ', ' > ', 1)->get ();
$res = db::table (' users ')->where (' id ', 1)->get ();
$res = db::table (' users ')->whereid (1)->get ();
User_age->whereuserage
$res = db::table (' users ')->where (' id ', ' < ', 3)->where (' username ', ' Qing ')->get ();
$res = db::table (' users ')->where (' id ', ' > ', 3)->orwhere (' username ', ' Qing ')->get ();
Username = Qing and (age>13 or sex=0)
$res = db::table (' users ')->where (' username ', ' Qing ')->where (function ($query) {
$query->where (' Age ', ' > ', '->orwhere ') (' sex ', 0);
})->get ();
$res = db::table (' users ')->wherebetween (' Age ', Array (0,15))->get ();
$res = db::table (' users ')->wherenotbetween (' Age ', Array (0,15))->get ();
$res = db::table (' users ')->wherein (' Age ', Array (23,30))->get ();
$res = db::table (' users ')->wherenot in (' Age ', Array (23,30))->get ();
*/
$res = db::table (' users ')->groupby (' Sex ')->orderby (' id ', ' DESC ')->having (' sex ', ' = ', 0)->get ();
$res = db::table (' users ')->limit (2,3)->get ();
$res = db::table (' users ')->skip (2)->take (1)->get ();
$res = db::table (' posts ')->join (' Users ', ' posts.user_id ', ' = ', ' users.id ')->get ();
$res = db::table (' posts ')->join (' Users ', function ($query) {
$query->on (' posts.user_id ', ' = ', ' users.id ');//->on (...);
})->get ();
/*
nested queries
$res = db::table (' users ')->where (function ($query) {
if (Input::get (' status ')) {
$query->wherestatus (input::get (' status '));
}
if (Input::get (' source ')) {
$query->wheresource (input::get (' source '));
}
})->get ();
*/
/*
$res = db::table (' users ')->whereexists (function ($query) {
$query->select (' * ')->from (' posts ')->whereraw (Db::raw (' users.id = posts.user_id '));
})->get ();
*/
$res = db::table (' users ')->where (' id ', ' > ', ' 2 ')->count ();
$res = db::table (' posts ')->where (' id ', 6)->decrement (' View_count ', 5);
$res =db::table (' posts ')->truncate ();
$res =db::table (' users ')->where (' id ', ' > ', 2)->remember (0.2)->get ();
echo "<pre>";
Print_r ($res);
echo "</pre>";
return ' OK ';
}