Welcome Guest, Not a member yet? Register   Sign In
table create problem using dbforge
#1

[eluser]mad82[/eluser]
Hi I got a problem when trying to create table using dbforge, the below is the error message I got, Any help to resolve the problem is greatly appreciated.
Quote:An Error Was Encountered

Field information is required for that operation.
Below are the two files I used
Code:
class Fileload extends CI_Controller
{
function _construct()
{
  parent::_construct();
  $this->load->helper(array('form','url'));
  
}

function index()

{
  $config['hostname'] = "localhost";
  $config['username'] = "root";
  $config['password'] = "test";
  $config['database'] = "login-db";
  $config['dbdriver'] = "mysql";
  $config['dbprefix'] = "";
  $config['pconnect'] = FALSE;
  $config['db_debug'] = TRUE;
  $config['cache_on'] = FALSE;
  $config['cachedir'] = "";
  $config['char_set'] = "utf8";
  $config['dbcollat'] = "utf8_general_ci";
  $this->load->database($config);
  $this->load->dbforge();
  $this->load->view('view_data');


}


}
?>
Here is the second file
Code:
<!DOCTYPE html>

&lt;html lang="en"&gt;

&lt;head&gt;

&lt;meta charset="utf-8"&gt;

&lt;title&gt;Welcome to CodeIgniter&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;? php
$fields = array(
                        'blog_id' => array(
                                                 'type' => 'INT',
                                                 'constraint' => 5,
                                                 'unsigned' => TRUE,
                                                 'auto_increment' => TRUE
                                          ),
                        'blog_title' => array(
                                                 'type' => 'VARCHAR',
                                                'constraint' => '100',
                                          ),
                        'blog_author' => array(
                                                 'type' =>'VARCHAR',
                                                 'constraint' => '100',
                                                 'default' => 'King of Town',
                                          ),
                        'blog_description' => array(
                                                 'type' => 'TEXT',
                                                 'null' => TRUE,
                                          ),
                );

$this->dbforge->add_field('$fields');
$this->dbforge->add_key('blog_id',TRUE);
if($this->dbforge->create_table('blog'))
{
echo"table created";
}

?&gt;
&lt;/body&gt;
&lt;/html&gt;
#2

[eluser]mad82[/eluser]
Ohhh... im really sorry I've passed the argument in quotes
$this->dbforge->add_field('$fields');. Removing the quotes solved the problem.




Theme © iAndrew 2016 - Forum software by © MyBB