[eluser]the future darlo manager[/eluser]
Starting to get my head around CodeIgniter now. The user guide is pretty good and I've bought myself a book. So far I am preferring it ahead of CakePHP as for legacy databases it seems to be a lot less hassle.
Anyway, a quick question about insets. In my old way of doing things with php I would write something like the following (the query isn't really important - the bit underneath is):
Code:
//Query to add the record into the history table
$add_history_query = "INSERT INTO cacdp_content_history (content_id, date, comment) VALUES ('$insert_id', NOW(), 'Created by $user_name')";
//Runs the query
$add_history_result = @mysql_query ($add_history_query);
//Checks the query ran okay
if ($add_history_result) {
echo "Query ran okay and record was inserted.";
} else {
echo "Something went wrong. Query Record was not inserted.";
}
Basically I got into a habit of checking if the query was ran okay and echoing out a certain message. I just want to know if the following is the right way to do it in the framework.
Controller
Code:
$data['page_title'] = "TEST INSERT PAGE";
$this->load->model('Test_model', '', TRUE);
$data['insert_user_query'] = $this->Test_model->insertUser($username, $passconf, $email);
if ($data['insert_user_query']) {
echo "Query was a success";
//I know I would load a view here with a success but for the purposes of this...
} else {
echo "Query failed";
//I know I would load a view here with a failure but for the purposes of this...
}
Model
Code:
class Test_model extends Model{
function Test_model(){
parent::Model();
}
function insertUser($username, $passconf, $email){
$query = $this->db->query("INSERT INTO people (username, password, email)
VALUES ('$username', '$passconf', '$email')");
return $query;
}
}
Sorry for asking but I'm just trying to get my knowledge of standard php up to the same level in the framework.