【问题标题】:FreeTDS error in PHP: The incoming tabular data stream (TDS) remote procedure call (RPC) protocol stream is incorrectPHP 中的 FreeTDS 错误:传入的表格数据流 (TDS) 远程过程调用 (RPC) 协议流不正确
【发布时间】:2012-12-03 23:42:49
【问题描述】:

我必须使用 ODBC 从 Arch Linux 连接到 MSSQL 服务器。 我使用 FreeTDS,并且使用 isql,它正在工作:

isql sqlexpress dev 开发

但不是在 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

祝你有美好的一天! 伴侣

【问题讨论】:

  • 您好!我尝试运行它: $a=odbc_exec($conn, 'select 1 as test_col;');但它也因同样的错误而失败。

标签: php odbc archlinux freetds


【解决方案1】:

这是我从 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 可能对您有很大帮助。

【讨论】:

    猜你喜欢
    • 2018-05-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-24
    • 1970-01-01
    • 2013-06-02
    • 1970-01-01
    • 1970-01-01
    • 2020-05-26
    相关资源
    最近更新 更多