2012-12-03 19 views
4

我必須使用ODBC連接到Arch Linux的MSSQL服務器。 我使用freetds的,並與ISQL,它的工作:PHP中的FreeTDS錯誤:傳入的表格數據流(TDS)遠程過程調用(RPC)協議流不正確

ISQL SQLEXPRESS開發開發

但不是在PHP。 我使用PHP在交互模式:


PHP > $conn = odbc_connect("sqlexpress", 'dev', 'Dev'); 
PHP > $a=odbc_exec($conn, 'SELECT * FROM measures;'); 
PHP Warning: odbc_exec(): SQL error: [FreeTDS][SQL Server]The incoming tabular data stream (TDS) remote procedure call (RPC) protocol stream is incorrect. Parameter 1 (""): Data type 0x00 is unknown., SQL state 37000 in SQLExecDirect in php shell code on line 1 

Warning: odbc_exec(): SQL error: [FreeTDS][SQL Server]The incoming tabular data stream (TDS) remote procedure call (RPC) protocol stream is incorrect. Parameter 1 (""): Data type 0x00 is unknown., SQL state 37000 in SQLExecDirect in php shell code on line 1 

我搜索了很多,但我找不到任何解決方案(甚至有人用同樣的問題)。 我的配置文件:

/etc/odbc.ini:

[sqlexpress] 
Server = 192.168.10.39 
Port = 1433 
Driver = FreeTDS 
Database = capture 
UserName = dev 
Password = Dev 

/etc/odbcinst.ini:

[FreeTDS] 
Description = FreeTDS driver 
Driver = /usr/lib/libtdsodbc.so 
Setup = /usr/lib/libtdsS.so 
Trace = Yes 
TraceFile = /tmp/freetds.log 
FileUsage = 1 
UsageCount = 1 

有一個愉快的一天! 伴侶

+0

您好!我嘗試運行:$ a = odbc_exec($ conn,'select 1 as test_col;'); 但它也出現同樣的錯誤。 – user1872567

回答

2

這是我的工作配置文件用於連接到從Ubuntu的一個MSSQL數據庫:

/etc/odbc.ini

# Define a connection to the MSSQL server. 
# The Description can be whatever we want it to be. 
# The Driver value must match what we have defined in /etc/odbcinst.ini 
# The Database name must be the name of the database this connection will connect to. 
# The ServerName is the name we defined in /etc/freetds/freetds.conf 
# The TDS_Version should match what we defined in /etc/freetds/freetds.conf 
[ebe] 
Description    = MSSQL Server 
Driver     = freetds 
Database    = my_database 
ServerName    = my_server_name 
TDS_Version    = 8.0 

/etc/odbcinst.ini

# Define where to find the driver for the Free TDS connections. 
[freetds] 
Description  = MS SQL database access with Free TDS 
Driver   = /usr/lib/i386-linux-gnu/odbc/libtdsodbc.so 
Setup   = /usr/lib/i386-linux-gnu/odbc/libtdsS.so 
UsageCount  = 1 

# Change the "no" to "yes" to enable ODBC logging. 
[ODBC] 
Trace   = no 
TraceFile  = /tmp/odbc.log 

/etc/freetds/freetds.conf

[global] 
     # If you get out-of-memory errors, it may mean that your client 
     # is trying to allocate a huge buffer for a TEXT field. 
     # Try setting 'text size' to a more reasonable limit 
     text size = 64512 

# Define a connection to the MSSQL server. 
[my_server_name] 
    host = my_server_domain_or_ip 
    port = 1433 
    tds version = 8.0 

最後,這裏是我的PHP連接字符串:

$this->db_connection = new PDO("dblib:dbname=my_database;host=my_server_domain_or_ip", 'username', 'password'); 

我相信設置TDS版本8.0可以給你一個很大的幫助。

+0

謝謝。錯誤是版本。 – user1872567

相關問題