• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
writing timestamp

#1
This should not be the problem that it is. I am trying to update the last_login date in my table, employees.
PHP Code:
           $query=$this->db->get_where('employees', array('employee_email'=>$email_key));
 
           if ($query->result_id->num_rows 0)
 
           {
 
               $row=$query->row();
 
               $camp=$row->campaign;
 
               $this->db->set('last_login'NOW(), FALSE);
 
               $this->db->where('employee_email'$email_key);
 
               $this->db->update('employees');

 
           
last_login is defined as 'date'. For some reason it remains all zeroes although this code does run. Is there any type of return code or error message from db->update? I looked in mysql_error.log but it looks OK. Perhaps NOW is returning a string or some other format which can't be written directly into last_login?  When I browse my table I see 0000-00-00 in last_login. 
Reply

#2
One possibility is

PHP Code:
if($query->result_id->num_rows 0)
{
 
   $row  $query->row();
 
   $camp $row->campaign;
 
   $now date('Y-m-d H:i:s');
 
   $this->db->set('last_login'$nowFALSE);
 
   $this->db->where('employee_email'$email_key);
 
   $this->db->update('employees');


Or the field could be defined like so
`last_login` int(11) UNSIGNED DEFAULT NULL,

And then set 'last_login" this way
PHP Code:
   $now time();
 
   $this->db->set('last_login'$nowFALSE); 

Or change the field to
`last_login` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP

Which makes it automatically update.
Reply

#3
OR load the date_helper and use it's method now()

I always do it like the last one that @dave friend mentioned
What did you Try? What did you Get? What did you Expect?

Joined the CodeIgniter Community in 2009.          ( Skype: insitfx )
Reply

#4
Works Great! I used the NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP which sure makes life easy! Thanks again.
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2018 MyBB Group.