MSSQL+ODBC+PHP = 0 rows in result

给你一囗甜甜゛ 提交于 2019-12-13 00:14:27

问题


I'm using remote MSSQL base via php + linux ODBC. All was fine, but today i wrote query with SET + PIVOT and got error:

[unixODBC][FreeTDS][SQL Server]SELECT failed because the following SET options have 
incorrect settings: 'ANSI_NULLS, QUOTED_IDENTIFIER, CONCAT_NULL_YIELDS_NULL,
ANSI_WARNINGS, ANSI_PADDING'. Verify that SET options are correct for use with indexed views 
and/or indexes on computed columns and/or filtered indexes and/or query notifications and/or 
XML data type methods and/or spatial index operations.

I tried to write SET ANSI_NULLS ON etc but it wont works, there is 0 fields in result. The same query executed directly on server via MSSQL studio works perfectly. Any idea where can be a problem? Thanks.

UPDATE:
freetds.conf

[syserver]
host =192.168.1.200
port = 1433
tds version = 7.0
AnsiNPW=YES
QuotedID=YES

odbc.ini

[sy_odbc]
Driver = FreeTDS
Description  = ODBC connection via FreeTDS
Trace = No
Servername = syserver
Database = Insy

odbcinst.ini

[FreeTDS]
Description = TDS driver (Sybase/MS SQL)
Driver = /usr/lib/odbc/libtdsodbc.so
Setup = /usr/lib/odbc/libtdsS.so
CPTimeout =
CPReuse =
FileUsage = 1

Before I got tds version=6.0, and after changing it up to 7.0 all errors such ANSI_NULLS gone, but I still have 0 rows in result. AnsiNPW=YES and QuotedID=YES do nothing for me. If try to change version to 8.0 in result of simple query i have ??????????. TDS_version=7.0 in odbc.ini also do nothing.

My query here. And my connection string is: $conn=odbc_connect('sy_odbc','t','t');

Update 2:
Some of my php pages stop working when i had changed TDS_version to 7.0 or 7.2, so i return it back to 6.0.
Connection string as you proposed don't work for me. At all. (I'm using mine more than year, and it was fine, before that issue)
Here is errorlog for problem query with 6.0 version (here we have ANSI_NULLS etc warnings)
Here is errorlog for problem query with 7.0 version (There is no warnings, but 0 rows in result)


回答1:


There are two more things I can think of Sergii:

1) Your connection string. The manual says your connection string should look like this:

$conn = odbc_connect('Driver={sy_odbc};Server=192.168.1.200;Database=Insy', $username, $password);

So I'd give that a try first and see if it helps.

2) Any time you are having problems with ODBC connections you should turn on logging so you can capture error messages. To do this add the following lines to your /etc/odbcinst.ini file:

[ODBC]
Trace     = yes
TraceFile = /tmp/odbc.log

If your query still doesn't work, edit your question and add the output from the odbc.log file (assuming there are error messages in it).



来源:https://stackoverflow.com/questions/15435927/mssqlodbcphp-0-rows-in-result

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!