CodeIgniter Forums
Converting a query using the Query Builder - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: Converting a query using the Query Builder (/showthread.php?tid=63039)



Converting a query using the Query Builder - jLinux - 09-18-2015

I have a query that right now is just a regular query executing via query(), I wanted to convert it using the Query Builder class

Heres the query as is:
PHP Code:
self::$db->query("UPDATE {$partition_table} SET {$column_name}=REPLACE({$column_name}, '{$current_value}', '{$new_value}') WHERE FIND_IN_SET('{$current_value}', {$column_name}) > 0" 

And that works fine, This is what I tried to convert it to:
PHP Code:
self::$db
    
->where("FIND_IN_SET('{$current_value}', {$column_name}) >"'0')
    ->
set($column_name"REPLACE({$column_name}, '{$current_value}', '{$new_value}')")
    ->
update($partition_table

And while that doesn't throw any errors, it will clean out the contents of any row it attempts to update...

Any idea what im doing wrong?

P.S. Before anyone says that it might be how I'm trying to use FIND_IN_SET, I've gotten it to work before, like so:
PHP Code:
$query self::$db
    
->where_in('page_id', (is_array($pages) ? $pages : [$pages]))
    ->
where("FIND_IN_SET('{$partition}', partitions) >"'0')
    ->
get('pages'); 



RE: Converting a query using the Query Builder - jLinux - 09-18-2015

Nvm, I got it working by just disabling the escape
PHP Code:
self::$db
    
->where("FIND_IN_SET('{$current_value}', {$column_name}) >"'0'FALSE)
    ->
set($column_name"REPLACE({$column_name}, '{$current_value}', '{$new_value}')"FALSE)
    ->
update($partition_table