User notification of a successful update in the encoder

I use these two lines to update my table using active codeigninter entries

$this->db->where('reference_number', $reference);
$this->db->update('patient', $data); 

what I want to check the weather, it successfully updates the table and accordingly I want to give a notification to the user, how can I check that a successful update has occurred with these rows? there is no clue in the user manual saying that by placing a line

if($this->db->update('patient', $data));

will give us true or false meaning, can we do this? or is there any other solution to this problem?

Regards, Rangana

+3
source share
4 answers

You can put such code in your model ...

function func() {
    $this->db->where('reference_number', $reference);
    $this->db->update('patient', $data); 

    $report = array();
    $report['error'] = $this->db->_error_number();
    $report['message'] = $this->db->_error_message();
    return $report;
}

_error_number _error_message mysql_errno mysql_error php.

, ...

$this->load->model("Model_name");
$report = $this->Model_name->func();
if (!$report['error']) {
  // update successful
} else {
  // update failed
}
+12

, $this->db->affected_rows(), , - .

+6

@ShiVik - _error_number() _error_message(), .

/config/database.php. db_debug = FALSE.

The way I handle this function on my system is to simply check the result returned by the ActiveRecord class using something like

if($this->db->update('patient', $data) === TRUE) {   
  $flash_data = array('type' => 'success', 'message'
=> 'Update successful!');
$this->session->set_flashdata('flash', $flash_data);
}

Although the use of the data system of the flash session is up to you :) You need to add the appropriate interface to this in your viewing files and configure as you wish, etc.

+2
source

use this

return ($this->db->affected_rows() > 0) ? TRUE : FALSE; 
+1
source

Source: https://habr.com/ru/post/1760023/


All Articles