Reputation: 12163
In Ci, I've got the following function. How do I test that the query successfully inserted without error's?
public function postToWall() {
$entryData = $this->input->post('entryData');
$myChurchId = $this->session->userdata("myChurchId");
$this->db->query("INSERT IGNORE INTO wallPosts (entryData, entryCreationDateTime, wpChurchId)
VALUES('$entryData', NOW(), '$myChurchId')");
}
Upvotes: 29
Views: 49814
Reputation: 714
Codeigniter 4:
$db = db_connect();
(your insert query)
return ($db->affectedRows() != 1) ? false : true;
Upvotes: 0
Reputation: 359
if you are using bootstrap on codeigniter try flash message or simply redirect
$added = $this->your_modal->function_reference($data);
if ($added) {
$this->session->set_flashdata('success', 'Added successfully.');
redirect('home');
} else {
$this->session->set_flashdata('error', 'Something wrong.');
redirect('home');
ON CONTROLLER
Upvotes: 1
Reputation: 3434
You can also do it using Transactions like this:
$this->db->trans_start();
$this->db->query("INSERT IGNORE INTO wallPosts (entryData, entryCreationDateTime, wpChurchId)
VALUES('$entryData', NOW(), '$myChurchId')");
$this->db->trans_complete();
if ($this->db->trans_status() === FALSE) {
return "Query Failed";
} else {
// do whatever you want to do on query success
}
Here's more info on Transactions in CodeIgniter!
Upvotes: 7