CodeIgniter Forums
Executing This Kind of SQL - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Executing This Kind of SQL (/showthread.php?tid=52834)



Executing This Kind of SQL - El Forum - 06-28-2012

[eluser]IanMcQ[/eluser]
I'd like execute this kind of SQL code in a CodeIgniter method:

Code:
SET @uids := '';

UPDATE table_name
   SET some_col= 'some_val'
WHERE some_col= 'some_val'
   AND ( SELECT @uids := CONCAT_WS(',', @uids, id) );

SELECT TRIM(LEADING ',' FROM @uids);

The issue is that $this->db->query() doesn't play friendly with this kind of SQL (for obvious reasons). How might I go about executing this "routine" through CodeIgniter's database library? I'm not familiar enough with CodeIgniter's Active Record to know myself.

Thanks in advanced. Smile I love CodeIgniter.


Executing This Kind of SQL - El Forum - 06-28-2012

[eluser]jmadsen[/eluser]
You can't send multiple sql statements via a single query in php, so you will need to write a stored procedure & execute that. Otherwise your @uids variable is "stateless" and will never be available for the later queries.