1

I've setup a linked MySQL server on our Microsoft SQL Server. I can run this query successfully in MSSQL Management Studio...

SELECT * FROM OPENQUERY(MYSQL, 'SELECT * FROM countries')

When I run this from a website in PHP though, I get this error...

Message: Failed to query SQL statement. Reason: Heterogeneous queries require the ANSI_NULLS and ANSI_WARNINGS options to be set for the connection. This ensures consistent query semantics. Enable these options and then reissue your query.

Any ideas what I can do to get this to work?

1 Answer 1

2

the workaround is to shift the “SET ANSI_WARNINGS OFF” statement just below the linked server call. And to be on the safer side apply the “SET ANSI_WARNINGS ON” statement at the end of the sp/query.

update

SET ANSI_WARNINGS ON

SET ANSI_NULLS ON

SELECT * FROM OPENQUERY(MYSQL, 'SELECT * FROM countries')

http://social.msdn.microsoft.com/Forums/en-US/sqldataaccess/thread/1d501b57-fc58-4fbe-9bec-6c38ad158a62

Sign up to request clarification or add additional context in comments.

4 Comments

Could you provide an example?
I'm not creating or using any stored procedure though. I'm just trying to run a simple select query using OPENQUERY().
I tried your updated answer and unfortunately it did not work. Any other ideas?
Ok I got it to work with the following PHP code. I'm using the Kohana LEAP ORM here, but the main point to getting this to work is to run these as separate queries in the same connection. $sql = "SELECT * FROM OPENQUERY(MYSQL, 'SELECT * FROM states') part"; $connection = DB_Connection_Pool::instance()->get_connection(new DB_DataSource('production_tm')); $connection->execute('SET ANSI_WARNINGS ON'); $connection->execute('SET ANSI_NULLS ON'); $res = $connection->query($sql);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.