I’m trying to update a row with a serialized array, but the row is not updating when I run the SQL statement below.
However when I just use a word like TEST instead it updates.
Any help on clearing this up would be greatly appreciated.
Returns 0 rows affected:
UPDATE lists SET col1 = 'a:9:{i:0;s:7:"English";i:1;s:7:"Spanish";i:2;s:6:"Korean";i:3;s:4:"Thai";i:4;s:0:"";i:5;s:0:"";i:6;s:0:"";i:7;s:0:"";i:8;s:0:"";}' WHERE list_id = '6'
Updates row correctly:
UPDATE lists SET col1 = 'TEST' WHERE list_id = '6'
Below is the Codeigniter PHP function:
public function update_field($table, $field, $value, $whereField = FALSE, $whereValue = FALSE )
{
$user_id = $this->session->userdata('user_id');
if ($whereField === FALSE) {
$sql = "UPDATE $table SET $field = '$value'";
$query = $this->db->query($sql);
} else {
$data = array(
$field => $value
);
$this->db->where($whereField, $whereValue);
$this->db->update($table, $data);
}
if ($this->db->_error_message()) {
echo 'Error Num: ' . $this->db->_error_number(); //returns 0 if query successful/no error
echo '<br />Message: ' . $this->db->_error_message();
}
}
the line is fine.
if you will try to update a field to it’s current value (ie you make no actual changes) then you will get 0 updated rows.
for example, if i have an employees table:
if you make no actual changes it returns 0