[eluser]auximage[/eluser]
I've run into an issue when using ODBC driver to connect to MSSQL. When my query has a series of complex joins, specifically joins on two different tables that share a field name (eg. orders.id and customers.id) but are not associated with each other, ODBC likes to 'lose' one of those fields. I've tried putting this complex SQL statement in to a stored procedure in hopes that it would mask the fact that these fields have the same name, even through they're in seperate tables. This trick, however, didn't work for me.
Example:
Code:
$sql = "select so.id as so_number, so.account_id, c.id as circuit_id
from serviceorders as so
left join circuits as c on so.ADDRESS_ID = c.ADDRESS_Id
where c.id = '12345'";
$query = $this->db->query($sql);
A dump of the query object looks like this:
Code:
Array
(
[0] => stdClass Object
(
[Id] => 211614
[account_id] => 10126204
)
[1] => stdClass Object
(
[Id] => 211614
[account_id] => 10126204
)
)
Note that so_number doesn't exist here as a returned field, instead it's only showing Id (from c.id). Before using CI, I had this issue but was able to pull the fields using odbc_result() and defining which field to pull (a very manual process).
Is there something in the CI ODBC bridge that would fix this problem and I've just been unable to find it? Any help would be appreciated as I've searched around a bit, from using sqlsrv driver (which I could not get to work properly) to trying using CI's mssql driver (no love there either).
I should note that this is a 'slimmed down' sql statment w/ only a single join here, the actual query is much more complex, but this demonstrates the error that I'm encountering.