简体   繁体   中英

Codeigniter database update issues

I am having issues in updating a table in my database (MySQL workbench).

The code in my model is the following:

function updateMail($new) {
    $data = array(
        'email' => $new
    );
    $this->db->where('email', $this->session->userdata('email'));
    $result = $this->db->update('person', $data);
    $error = $this->db->error();
    return $error;
}

My controller then places the return value in $result, and chechs if(!isset($result)) .

the problem is that sometimes the table updates, sometimes it doesn't, but the error is always set.

The table basically contains persons with an id, name, firstname, password, username, email, and patient field.

Am I doing something wrong? Or is there a way a can display the error message it throws?

Instead of error you have to check number of affected row in your query

function updateMail($new) {
    $data = array(
        'email' => $new
    );
    $this->db->where('email', $this->session->userdata('email'));
    $result = $this->db->update('person', $data);
    $afftectedRows = $this->db->affected_rows();
    if ($afftectedRows > 0) {
        return TRUE;
    } else {
        return FALSE;
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM