CodeIgniter Forums
Problem using NOW() in Database - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forum-21.html)
+--- Thread: Problem using NOW() in Database (/thread-33026.html)



Problem using NOW() in Database - El Forum - 08-12-2010

[eluser]mashary[/eluser]
here is my code insdie my own library

Code:
$this->ci->db->where('user',$this->ci->session->userdata('username'));
        $this->ci->db->update('users',array('is_log'=>'0','last_log',NOW()));

i got following error
Fatal error: Call to undefined function now() in C:\xampp\htdocs\fifi\system\application\libraries\authen.php on line 34

when i change my code into like this
adding bracket NOW() with quote

Code:
$this->ci->db->where('user',$this->ci->session->userdata('username'));
        $this->ci->db->update('users',array('is_log'=>'0','last_log','NOW()'));

sql produce like this

Quote:UPDATE `users` SET `is_log` = '0', `last_log` = 'NOW()' WHERE `user` = 'mashary'

how can i put now() function?


sorry poor english


Problem using NOW() in Database - El Forum - 08-12-2010

[eluser]mi6crazyheart[/eluser]
Try this one...
Code:
$userName = $this->ci->session->userdata('username');

$this->db->set('is_log', 0);
$this->db->set('last_log','NOW()',false);
$this->db->where('user', $userName);
$this->db->update('users');



Problem using NOW() in Database - El Forum - 08-13-2010

[eluser]mashary[/eluser]
ok thanks man, it's work