Welcome Guest, Not a member yet? Register   Sign In
Active Record and CURDATE()
#1

[eluser]al404[/eluser]
i'm using active record for a query but i also would like to set a value of a filed to CURDATE() via SQL, it doesn't work eather with or without quote

how can i do that?

$data = array(
'title' => $title,
'datein' => 'CURDATE()',
other fields...
);

$this->db->update('news', $data);
#2

[eluser]meigwilym[/eluser]
I can't find anything in the user guide, but you could always try

Code:
$data = array(
  ‘title’ => $title,
  ‘datein’ => date('Y-m-d'),
  // other fields…
);
    
$this->db->update(‘news’, $data);

Mei
#3

[eluser]everdaniel[/eluser]
you might need to use the set() method to prevent CI from escaping your mysql function, so:

Code:
$this->db->set('title', $title);
$this->db->set('dateing', 'CURDATE()', FALSE);
$this->db->update('news');
#4

[eluser]al404[/eluser]
@meigwilym

that's may work but i may need in other occasion to use MySQL functions
#5

[eluser]kgill[/eluser]
If you want to use built-in functions you're pretty much going to have to abandon active record, anything you send is going to be quoted and treated as a string. Your other option is to modify the driver file and add a line to the _insert and _update functions to replace 'CURDATE()' with CURDATE().
#6

[eluser]everdaniel[/eluser]
[quote author="kgill" date="1232059522"]If you want to use built-in functions you're pretty much going to have to abandon active record, anything you send is going to be quoted and treated as a string. Your other option is to modify the driver file and add a line to the _insert and _update functions to replace 'CURDATE()' with CURDATE().[/quote]

You don't need to change any CI core file, as I said, you just need to use the set() method and pass FALSE as the third argument and that's it, CI won't quote the string.
#7

[eluser]kgill[/eluser]
Well now that's interesting... Now I have to figure out why the version of active record on our production system does not have that 3rd param. It was updated to 1.6.3 last year, someone is not going to be happy to see me.
#8

[eluser]al404[/eluser]
ok this way works fine

Code:
$query = array(
  ‘title1’ => $title1,
  ‘title2’ => $title2
);

$this->db->set($query);        
$this->db->set('datein', 'CURDATE()', FALSE);
      
$this->db->update(‘news’);




Theme © iAndrew 2016 - Forum software by © MyBB