4

ODBCを使用してArchLinuxからMSSQLサーバーに接続する必要があります。私はFreeTDSを使用していますが、isqlを使用すると、次のように機能します。

isql sqlexpress dev 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

良い1日を!メイト

4

1 に答える 1

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 に設定すると、大きな助けになると思います。

于 2012-12-03T14:28:34.257 に答える