2011-01-11 104 views
0

我有這個網站幾個月建成,我剛開的Kohana 3.我只是想這K2.4查詢構建器K3查詢生成器轉換。我如何從Kohana的2.4這個查詢生成器更改爲Kohana的3?

return DB::select(array('posts.id', 'posts.created', 'posts.uri', 'posts.price', 'posts.description', 'posts.title', 
       'image_count' => db::expr('COUNT(images.id)'))) 
     ->from('posts') 
     ->join('images')->on('images.post_id', '=', 'posts.id') 
     ->group_by(array('posts.id')) 
     ->order_by('posts.id', 'DESC') 
     ->limit($limit) 
     ->offset($offset) 
     ->execute(); 

回答

1

你需要做的唯一的變化,就是從DB下降周邊陣列::選擇(),併爲別名域,使用數組

在Kohana3的查詢構建器接受任意數量的參數,見http://kohanaframework.org/guide/database/query/builder

return DB::select('posts.id', 'posts.created', 'posts.uri', 
      'posts.price', 'posts.description', 'posts.title', 
      array('COUNT("images.id")', 'image_count')) 
    ->from('posts') 
    ->join('images')->on('images.post_id', '=', 'posts.id') 
    ->group_by(array('posts.id')) 
    ->order_by('posts.id', 'DESC') 
    ->limit($limit) 
    ->offset($offset) 
    ->execute(); 
+0

事實上,我這一個小時前。我只是等着別人給的答案,所以我可以接受;) – 2011-01-11 13:20:28