0
votes

trying to update the session data in the session table for all session ids but been struggling for few hours.

$_data = array('sess_data'  => 'abc');
$this->db->where('sess_id', $_sid);
$this->db->update($_table, $_data);

The code below give me a value of 1 which indicates the above code does works.

$this->db->affected_rows();  

but when i view the database through phpmyadmin, nothing is updated. There are no mysql error messages generated. pls advise how to proceed further.

Edited

UPDATE `sessions` SET `sess_data` = 'abc' WHERE `sess_id` = 'skavnhgk84712r06npem76snu2'  

Updated:

Strange, today I add 2 more session records and it only updates the 2nd & 3rd records, the 1st record does not change. Why is it so? I'm using foreach loop and below are the generated query.

UPDATE `sessions` SET `sess_data` = 'ABC' WHERE `sess_id` = 'skavnhgk84712r06npem76snu2'  no success!  
UPDATE `sessions` SET `sess_data` = 'ABC' WHERE `sess_id` = 'skavnhgk84712r06npem76snu3'  success  
UPDATE `sessions` SET `sess_data` = 'ABC' WHERE `sess_id` = 'skavnhgk84712r06npem76snu4'  success  
1
can you echo what the value of $_sid and compare it to your db? - Eddie
i change the above code to select * from table where sess_id = $_sid and it give me the correct result. so i believe the $_sid value is ok. - user1884324
Use, $this->db->last_query() to view the query generated. - Nil'z
Why just not use : $this->db->update($_table, $_data, array('sess_id' => $_sid)) ? - Vincent Decaux
i edited my post to add in the last query generated. Thanks Vincent but it does not solve my problem. - user1884324

1 Answers

0
votes

I think this should work.

$data = array(
           'title' => $title,
           'name' => $name,
           'date' => $date
        );
$this->db->where('id', $id);
$this->db->update('mytable', $data); 

For more reference visit this site:

http://ellislab.com/codeigniter/user-guide/database/active_record.html