USE statement and odbc_execute vs. odbc_exec
Posted: Wed Sep 30, 2009 9:00 am
When I send the following query to our Microsoft SQL Server database using odbc_exec:
use mydatabase
select 1 from mytable
it works fine. But if I use odbc_prepare followed by odbc_execute, the query fails, saying that table "mytable" was not found. The "USE" statement is not having an effect. Does anyone have an explanation?
We are using Easysoft's ODBC-to-SQL-Server driver, if it matters. Also this is PHP 5.1.6 and SQL Server 2005 & 2008. The specific error message is:
SqlServerQuery: [unixODBC][Easysoft][SQL Server Driver][SQL Server]Invalid object name 'mytable'.
Note: I did test that multiple statements do work in a single odbc_execute call, so the problem is not caused simply by having multiple statements:
select 1 from mytable
select 2 from mytable
use mydatabase
select 1 from mytable
it works fine. But if I use odbc_prepare followed by odbc_execute, the query fails, saying that table "mytable" was not found. The "USE" statement is not having an effect. Does anyone have an explanation?
We are using Easysoft's ODBC-to-SQL-Server driver, if it matters. Also this is PHP 5.1.6 and SQL Server 2005 & 2008. The specific error message is:
SqlServerQuery: [unixODBC][Easysoft][SQL Server Driver][SQL Server]Invalid object name 'mytable'.
Note: I did test that multiple statements do work in a single odbc_execute call, so the problem is not caused simply by having multiple statements:
select 1 from mytable
select 2 from mytable