Question

這段程式碼還可以重構嗎?

if ($query = $this->database->get(
    'game',    // 資料表名稱
    array(    // where
        'game.id' => $game_id,
    ),
    array(),    // order_by
    array(),    // join
    array(    // select
        'game.id',    // 遊戲序號
        'game.name',    // 遊戲名稱
    ),
    1
)) {
    ...
    ...
    ...
}

這樣是否比較容易閱讀?

$result = $this->database->from('game')
                        ->select('id, name')
                        ->where('id', $game_id)
                        ->get();

if ($result) {
    ...
    ...
}

Last updated