CURDATE() and INTERVAL in codeigniter |
[eluser]Thiago Leao[/eluser]
Hi friends, I have a question. I have this query: Code: INSERT INTO buy (id_products, date_start, date_finish) VALUES ('1', CURDATE(), CURDATE() + INTERVAL 30 DAYS) I want this query in codeigniter, as I do? I tried it but did not work: Code: function insertBuy($id_products){ thank guys!
[eluser]InsiteFX[/eluser]
He's using db->set->($array) So you do not need to pass it to the insert method.
[eluser]Bhashkar Yadav[/eluser]
thanks InsiteFX. well, i think here is error : Code: $array = array('id_products' => $id_products, 'date_start' => CURDATE(), 'date_finish' => 'CURDATE() + INTERVAL 30 DAYS'); and CURDATE() should also be within quotes. Code: $array = array('id_products' => $id_products, 'date_start' => 'CURDATE()', 'date_finish' => 'CURDATE() + INTERVAL 30 DAYS');
[eluser]Thiago Leao[/eluser]
[quote author="Bhashkar" date="1328940458"]thanks InsiteFX. well, i think here is error : Code: $array = array('id_products' => $id_products, 'date_start' => CURDATE(), 'date_finish' => 'CURDATE() + INTERVAL 30 DAYS'); and CURDATE() should also be within quotes. Code: $array = array('id_products' => $id_products, 'date_start' => 'CURDATE()', 'date_finish' => 'CURDATE() + INTERVAL 30 DAYS'); Hi friend, i had already done so, and still did not work! =/
[eluser]InsiteFX[/eluser]
You can try this, but then you will need to use set on all the fields. Code: $this->db->set('date_finish = DATE_ADD(CURDATE(), INTERVAL 30 DAY)');
[eluser]Mauricio de Abreu Antunes[/eluser]
How to print string SQL created by Active Record class? Maybe you need to print your SQL and run it.
[eluser]Mauricio de Abreu Antunes[/eluser]
Anyway, i use SQL Strings like: Code: $sql = 'select * from user where iduser = ?'; I just use Active Record Class (CI string builder) when i dont have any parameters. Active Records escapes strings, but i think it don't bind parameters.
[eluser]InsiteFX[/eluser]
Quote:How to print string SQL created by Active Record class? CodeIgniter User Guide - Query Helper Functions See: Code: $this->db->insert_string();
|
Welcome Guest, Not a member yet? Register Sign In |