Codeigniter, update value with "CURRENT_TIMESTAMP"

Asked

Viewed 54 times

0

Good, I want to update a table where in one of the variables I want to insert the value "CURRENT_TIMESTAMP".

In a normal situation just send the value as a string and sql would interpret it and translate it to the current date.

The point is you’re not doing it and I don’t understand why.

My code is as follows and I am using the Codeigniter framework.

public function resetlogin(){
        $this->db->set('ulogin', 'CURRENT_TIMESTAMP');
        $this->db->set('tentativa1', 0);
        $this->db->set('tentativa2', 0);
        $this->db->where('codigo',18990);
        $this->db->update('usuario');

    }

All other values are updated normally.

Someone can identify the problem?

  • you have already tried to leave the table structure to do that automatic insertion ? where you define in the DB that the column ulogin and kind timestamp. Or yourself that insert ?

  • what is inserted in the field ulogin when that code is executed?

  • 0000-00-00 00:00

  • I haven’t tried automatic insertion yet, I’ll try tomorrow

2 answers

0


You need to disable the escape to use MYSQL functions, otherwise Codeigniter will do:

UPDATE usuario SET ulogin = 'CURRENT_TIMESTAMP'

The third parameter of the method set is boolean (TRUE by default) to enable or disable escape

$this->db->set('ulogin', 'CURRENT_TIMESTAMP', FALSE);

0

Have you tried:

$this->db->set('ulogin', 'CURRENT_TIMESTAMP', FALSE);

Or

$this->db->set('ulogin', 'NOW()', FALSE);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.