您是否安装了 unixODBC 模块? sudo apt-get install unixodbc
您是否为 PHP 安装了 ODBC 支持? sudo apt-get install php5-odbc
您是否在 odbc.ini 和 odbcinst.ini 文件中定义了与 Microsoft Sequel Server 的连接?
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
[msft_sql_server]
Description = The Microsoft Sequel Server
Driver = freetds
Database = XXXXXXXXXX
ServerName = msft_sql_server
TDS_Version = 8.0
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
然后您的 PHP 连接将如下所示:
$db_connection = new PDO("dblib:dbname=$database_server;host=$database_server", $db_username, $db_password);
您可以使用 iSQL 程序测试上述设置,以确保您可以建立连接。
如果您仍然无法从 Linux 服务器连接到 MSFT 服务器 - 是否有防火墙阻碍?您确定您拥有有效的用户凭据吗?MSFT 服务器会接受来自远程客户端的连接吗?