CodeIgniter updates num fields but does not update text fields

Viewed 9

I ama trying to update some values in a table. Some lines have numbers only and some has alpha-numeric texts. I can update number only fields but I get syntax error while trying to update a name for example.

This is my update function in the model:

public function update_setting($id, $myValue)
{
    $this->db->set('myValue', $myValue, FALSE)->where('id', $id)->update('settings');
}

I get the following error:

You have an error in your SQL syntax;....

UPDATE settings SET myValue = Some Text here WHERE id = '19'

The problem is so simple I guess. It is about the apostrophes. According to SQL query string in the error message there is no apostrophes embracing the text value.

1 Answers

I've found the error:

There is a FALSE parameter value which omits escaping strings in the function set.

public function update_setting($id, $myValue)
{
    $this->db->set('myValue', $myValue, FALSE)->where('id', $id)->update('settings');                           |
}                                          |
                         -------------------

Now It is working after deleting FALSE:

public function update_setting($id, $myValue)
{
    $this->db->set('myValue', $myValue)->where('id', $id)->update('settings');
}
Related