[eluser]fell0206[/eluser]
Hello everybody, I have a problem with the active record of insert.
My table have a "Root" of column(not null), it have a default value(0), I create a class, and I use "$this->db->insert('mytable',$data);" to insert the record, but when the variable "Root" is null, then the error will occur.
How can I fix this error!! Thanks~
MyTable:
Code:
CREATE TABLE IF NOT EXISTS `test` (
`A` int(1) NOT NULL,
`Root` int(1) NOT NULL DEFAULT '1'
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
MyClass:
Code:
class MyClass{
public $A;
public $Root;
}
Controller:
Code:
...
$myClass=new MyClass();
$this->load->model('test_model');
$myClass->$A=$this->input->post('A');
$this->test_model->add($myClass);
...
Model:
Code:
...
function add($myClass){
$this->db->insert('test',$myClass);
}
...