Welcome Guest, Not a member yet? Register   Sign In
$this->db->query not returning a value...
#1

[eluser]GaryTheLlama[/eluser]
Here's the code I'm running.

Code:
$query = $this->db->query("DECLARE @tmp TABLE (ContactID UNIQUEIDENTIFIER)
INSERT INTO tblCD (" . ArrayToString($fieldsCDArray) . ")
OUTPUT Inserted.ContactID INTO @tmp
VALUES (" . ArrayToDBString($valuesCDArray) . ")
INSERT INTO tblCCO (ContactID, " . ArrayToString($fieldsCCOArray) . ")
VALUES ((SELECT ContactID FROM @tmp), " . ArrayToDBString($valuesCCOArray) . ")
SELECT ContactID FROM @tmp");

$result = $query->row();

I've ran $this->db->last_query() to verify that the SQL code actually works in SQL server. It ends up returning a single row, as expected. But I get nothing returned from CodeIgniter with the above code. I've also tried running it with result() and result_array() just for kicks, and still nothing.

Does CodeIgniter not like returning results from a query with more than one statement in it or do I have to get the result a different way? (For anyone asking, I'm just trying to get the last inserted id but it's a GUID so I can't use $this->db->insert_id().

Any help or suggestions would be appreciated. Thanks.

Edit: Also, ignore the ArrayToDBString($fieldsCCOArray), those are definitely not the issues since, like I said, I've printed the last query and ran it through SQL successfully. Also, the result I get when running it through SQL is a single column called ContactID.




Theme © iAndrew 2016 - Forum software by © MyBB