Answer by Mitchell McKenna for Code Igniter Load Database seem to stop process thread

October 25 2010, 6:03am

You need to load the db in in model or in the auto-config (see Anzeo's post) Can't access model like $this->Account_model->userId = 'asd'; - need to call functions You can't insert $this (also unsafe) Change Enabled field in db to type BOOLEAN (TinyInt is unnecessary)

The following should get your started... The Controller:

class SignUp extends Controller { function SignUp(){ parent::Controller(); } function createUser(){ echo 'processing'; $this->load->model('Account_model'); $result = $this->Account_model->insert($userId = 'asd', $userName = 'test_user', $enabled = 'true', $startOfDay = time()); echo ($result == TRUE) ? 'insert successful' : 'insert failed'; } }

The Model:

class Account_model extends Model { function Account_model(){ parent::Model(); $this->db = $this->load->database('default', TRUE); } function add_user($userId, $userName, $requestToken = '', $accessToken = '', $enabled = 'false', $startOfDay = '', $endOfDay = '') { $user = array( 'UserId' => $userId, 'UserName' => $userName, 'requestToken' => $requestToken, 'accessToken' => $accessToken, 'Enabled' => $enabled, 'startOfDay' => $startOfDay, 'endOfDay' => $endOfDay ); $this->db->insert('accounts', $user); return ($this->db->affected_rows() > 0) ? TRUE : FALSE; } } }