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;
}

转载于:https://my.oschina.net/u/3268486/blog/1841275

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值