[eluser]novice32[/eluser]
On occasion, my CI application throws a very strange and baffling error message. My front-end application is Adobe Flex based and passes data to the CI app via
HTTP post methods. In the case of this one model method,
AddItem, it throws a DB error message.
------log files for one day----
ERROR - 2010-07-02 15:01:41 --> Query error: Column 'ItemClientID' cannot be null
ERROR - 2010-07-02 15:01:51 --> Query error: Column 'ItemClientID' cannot be null
ERROR - 2010-07-02 15:03:12 --> Query error: Column 'ItemClientID' cannot be null
-----------
It's important to note this happens
RARELY (once a week at most). The method has been called successfully 2,000+ times, since the launch of the application. Further confusing this is
ItemClientID is assigned at login (in the "user" table for each login) and should never be "null". (ItemClientID is essentially, used to identify which client inserted the record).
Am I incorrectly validating ItemClientID ??
Code:
<?php
/***** CONTROLLER CLASS *****/
class Item extends Controller {
private $ClientID; //each client has a unique id
function Item() {
parent::Controller();
......
$this->ClientID = $this->input->post('ClientID'); //reads value when HTTP post is performed to controller's AddItem method
if (empty($this->ClientID)) {
echo json_encode(array('error'=>'ClientID is required'));
return; //exit
}
....
}
function AddItem() {
...
// read a bunch of HTTP post values and validate.
.....
$this->load->model('Item_model', '', TRUE);
$rowcount = $this->Item_model->AddItem($this->ClientID,$ItemDescription,....);
echo json_encode(array('rowcount'=>$rowcount));
}
}
<?php
/***** MODEL METHOD ****/
class Item_model extends Model {
function Item_model() {
parent::Model();
}
function AddItem($ItemClientID,$ItemDescription,...) {
//array fields are required in the db schema
$data = array(
'ItemClientID' => $ItemClientID ,
'ItemDescription' => $ItemDescription ,
....
);
....
$this->db->insert('item', $data);
return $this->db->affected_rows();
}
}