Welcome Guest, Not a member yet? Register   Sign In
Database Forge Class does not create the table
#1

Hi all,
I try to create table into my db but i can't. System give no error messages. Any suggestion? Smile


CONTROLLER
PHP Code:
<?php
defined
('BASEPATH') OR exit('No direct script access allowed');

class 
Tables extends CI_Controller {
 
       public function __construct()
 
       {
 
               parent::__construct();
 
               $this->load->model('table_model');
 
       }
 
       public function index()
 
       {
 
               $fields = array(
 
                   'blog_id' => array(
 
                       'type' => 'INT',
 
                       'constraint' => 5,
 
                       'unsigned' => TRUE,
 
                       'auto_increment' => TRUE
                    
),
 
                   'blog_title' => array(
 
                           'type' => 'VARCHAR',
 
                           'constraint' => '100',
 
                           'unique' => TRUE,
 
                   ),
 
                   'blog_author' => array(
 
                           'type' =>'VARCHAR',
 
                           'constraint' => '100',
 
                           'default' => 'King of Town',
 
                   ),
 
                   'blog_description' => array(
 
                           'type' => 'TEXT',
 
                           'null' => TRUE,
 
                   ),
 
               );
 
               $this->table_model->create_table($fields);   
        
}


MODEL

PHP Code:
<?php
defined
('BASEPATH') OR exit('No direct script access allowed');
class 
Table_model extends CI_Model {

 
   public function __construct()
 
   {
 
       $this->load->database();
 
       $this->load->dbforge();
 
   }
 
   public function create_table($data)
 
   {
 
       //print_r($data);
 
       $this->dbforge->add_field($data);
 
       $this->dbforge->create_table('mytable',TRUE);
 
   }

Reply


Messages In This Thread
Database Forge Class does not create the table - by ven0m - 03-30-2019, 05:47 AM



Theme © iAndrew 2016 - Forum software by © MyBB