Welcome Guest, Not a member yet? Register   Sign In
This about update_string/insert string
#1

[eluser]Lima[/eluser]
How can I built query using db->update_string() or db->insert_string() method
Query result has value from database function
Ex:
UPDATE my_table SET field1=NOW(), field2=db_function('param1', 'param2') WHERE id='20100205';

Thank You
#2

[eluser]theprodigy[/eluser]
Quote:UPDATE my_table SET field1=NOW(), field2=db_function(‘param1’, ‘param2’) WHERE id=‘20100205’;

Code:
$data = array('field1' => 'NOW()', 'field2' => $this->db_function($param1, $param2));

$where = "id = $id";

$str = $this->db->update_string('my_table', $data, $where);

should do it, but I'm not exactly sure about the NOW() part as this function automatically escapes values for safer queries.

Test run produced:
Code:
$param1 = 'param1';
$param2 = 'param2';
$id = 'my_id';

private function db_function($param1, $param2)
{
    return $param1 . ', ' . $param2;
}

$data = array('field1' => 'NOW()', 'field2' => $this->db_function($param1, $param2));

$where = "id = $id";

echo $this->db->update_string('my_table', $data, $where);

//This above test code produced the following string:
//UPDATE `my_table` SET `field1` = 'NOW()', `field2` = 'param1, param2' WHERE id = my_id
#3

[eluser]Lima[/eluser]
I think it is not possible to generate that query using update_string() method
#4

[eluser]Bart v B[/eluser]
It is nog possible like that way i think.

I had the same problem last week.

Take a look at this threat:
http://ellislab.com/forums/viewthread/73126/

This should solve youre problem ;-)
#5

[eluser]theprodigy[/eluser]
Good call.

Thanks for the info.




Theme © iAndrew 2016 - Forum software by © MyBB