ci 動態建立數據庫

private function crBoxLogTb(){
    //如數據配置文件有配置表前綴,這裏會自動追加
    $table      = 'log_'.date('Y_m_d');
    $isExist    = $this->db->table_exists($table);
    if($isExist){return $table;}

    //表字段
    $fields = array(
        'id'            => array(
            'type'              => 'INT',
            'constraint'        => 11,
            'unsigned'          => TRUE,
            'auto_increment'    => TRUE,
            'comment'           => "自增ID"
        ),

        'uid'           => array(
            'type'              => 'BIGINT',
            'constraint'        => '20',
            'comment'           => "用戶ID"
        ),

        'log_id'        => array(
            'type'              => 'INT',
            'constraint'        => 11,
            'unsigned'          => TRUE,
            'comment'           => "日誌描述id"
        ),

        'addtime'       => array(
            'type'              => 'INT',
            'constraint'        => 11,
            'unsigned'          => TRUE,
            'comment'           => "添加時間"
        ),
    );

    //索引
    $indexF           = array('uid',);

    //表引擎、別名
    $attributes         = array('ENGINE' => 'InnoDB','COMMENT'=>"'用戶、遊客登錄表'");

    //主鍵
    $primary            = 'id';

    //加載數據庫工廠類
    $this->myforge   = $this->load->dbforge($this->db, TRUE);

    $this->myforge->add_field($fields);
    $this->myforge->add_key($primary, TRUE);
    $this->myforge->add_key($indexF);
    $this->myforge->create_table($table, TRUE,$attributes);

    $isExist    = $this->db->table_exists($table);
    if($isExist){return $table;}

    return false;
}
相關文章
相關標籤/搜索