Welcome Guest, Not a member yet? Register   Sign In
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. 
proof that an old dog can learn new tricks
Reply
#2

(This post was last modified: 04-11-2018, 03:05 PM by dave friend.)

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

(This post was last modified: 04-12-2018, 03:51 AM by InsiteFX.)

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 CodeIgniter Community 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.
proof that an old dog can learn new tricks
Reply
#5

(This post was last modified: 04-26-2018, 11:06 AM by richb201.)

I am still having a problem with this. What do I need to get the timestamp to update? i am using NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP

               $this->db->set('photo',$json->photo);  //save this guys photo for the org chart
               $this->db->where('employee_email', $email_key);
               $this->db->update('employees');

Attached Files Thumbnail(s)
   
proof that an old dog can learn new tricks
Reply
#6

This is how it is done.

Code:
    `created_at`    datetime                        default current_timestamp,
    `updated_at`    datetime                        default current_timestamp on update current_timestamp,

Hope that helps.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#7

Thanks Insite. But what do I need to do? Do I do a where and then an update? Or should I do a replace? I made the changes but still it is not working.
proof that an old dog can learn new tricks
Reply
#8

It should update on any data saved to the table.

update or replace.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#9

(04-26-2018, 01:39 PM)richb201 Wrote: Thanks Insite. But what do I need to do? Do I do a where and then an update? Or should I do a replace? I made the changes but still it is not working.

mysql version?
Reply
#10

15.1 distrib 10.1.19-MariaDB for win 32
proof that an old dog can learn new tricks
Reply




Theme © iAndrew 2016 - Forum software by © MyBB