天天看點

ZenTaoPHP非常輕量的MVC PDO類

調用方法:

ZenTaoPHP非常輕量的MVC PDO類

<?php  

include 'config.php';  

include 'dao.class.php';  

$dao = new dao();  

一、查詢語句:

ZenTaoPHP非常輕量的MVC PDO類

$dao->select('*')->from('user')->where('account')->eq('wwccss')->fetch();  

$dao->select('*')->from('user')->where('id')->gt(10)->andwhere('age')->lt(20)->orderby('id desc')->limit('1,10')->fetchall()  

條件語句:

ZenTaoPHP非常輕量的MVC PDO類

$dao->select('*')->from('user')->where('id')->gt(10)->beginif($class == 'online')->andwhere('status')->eq('online')->fi()->fetchall();  

二、插入語句:

ZenTaoPHP非常輕量的MVC PDO類

$user->account = 'wwccss';  

$user->password = '123456';  

$dao->insert('user')->data($user)->exec();  

return $dao->lastinsertid();  

或者:

ZenTaoPHP非常輕量的MVC PDO類

$dao->insert('user')  

  ->set('account')->eq($account)  

  ->set('password')->eq($password)  

  ->exec();  

三、更新語句:

ZenTaoPHP非常輕量的MVC PDO類

$dao->update('user')->data($user)->where('id')->eq($userid)->limit(1)->exec();   

ZenTaoPHP非常輕量的MVC PDO類

$dao->update('user')  

  ->exec()  

四、replace語句

ZenTaoPHP非常輕量的MVC PDO類

$dao->replace('user')->data($user)->exec();    

五、删除語句:

ZenTaoPHP非常輕量的MVC PDO類

$dao->delete()->from('user')->where('id')->eq($userid)->exec();  

六、左連接配接

ZenTaoPHP非常輕量的MVC PDO類

$dao->select('t1.*, t2.*')->from('user')->alias('t1')->leftjoin('usergroup')->alias('t2')->on('t1.account = t2.account')->fetchall();  

六、其他便利的方法:

ZenTaoPHP非常輕量的MVC PDO類

$dao->findbyaccount($account)->from('user')->fetch(); // 魔術方法,按照account進行查詢。  

$dao->select('*')->from('user')->fetchall('account');     // 傳回的結果中,以account為key。  

$dao->select('account, realname')->from('user')->fetchpairs();     // 傳回account=>realname的鍵值對。  

$dao->select('class, account, realname')->from('user')->fetchgroup('class');     // 按照所屬的class進行分組。