0

我有 Windows 和 Linux 服务器。SQL Server 2005 安装在 Windows 机器上,我想使用 PHP 从我的其他 Linux 服务器连接到 Windows 数据库。服务器位于不同的位置。

我已经尝试了一切,但没有成功。这是我的 phpinfo 输出:

Configure Command    './configure' '--with-apxs2' '--with-curl=/usr/local/lib' '--with-gd' '--with-ttf' '--with-gettext' '--with-jpeg-dir=/usr/local/lib' '--with-freetype-dir=/usr/local/lib' '--with-kerberos' '--with-openssl' '--with-mcrypt' '--with-mhash' '--with-mysql=/usr' '--with-mysqli=/usr/bin/mysql_config' '--with-pdo-mysql=/usr' '--with-unixODBC=/usr' '--with-pcre-regex=/usr/local' '--with-pear' '--with-png-dir=/usr/local/lib' '--with-xsl' '--with-mssql=/usr/local/freetds' '--with-pdo-dblib=/usr/local' '--with-zlib' '--with-zlib-dir=/usr/local/lib' '--with-iconv=/usr/local' '--enable-bcmath' '--enable-calendar' '--enable-exif' '--enable-ftp' '--enable-gd-native-ttf' '--enable-magic-quotes' '--enable-safe-mode' '--enable-soap' '--enable-sockets' '--enable-mbstring' '--enable-zip' '--enable-wddx'

启用了 ODBC 支持、dblib、Mssql。

Windows 机器上没有防火墙。我已经从调制解调器转发了 1433 端口。我可以从我的机器(本地)上的 Windows sql studio 和 WAMP 连接,但无法从 PHP 连接:(

有什么建议么?

4

1 回答 1

0

您是否在 Linux 服务器上配置了这些文件?(这些取自 Ubuntu 12.04 服务器)

/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
[mssql]
Description             = MSSQL Server
Driver                  = freetds
Database                = MyDatabase
ServerName              = mssql
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

/etc/freetds/freetds.conf

# The basics for defining a DSN (Data Source Name)
# [data_source_name]
#       host = <hostname or IP address>
#       port = <port number to connect to - probably 1433>
#       tds version = <TDS version to use - probably 8.0>

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

我已经阅读了导致问题的 tds 版本的几个帐户。似乎 8.0 字最好,但我也看到人们说他们可以使用 7.5 和 7.0。

这是一个示例 PDO 连接:

$pdo = new PDO("dblib:dbname=$database_name;host=$database_server", $temp_username, $temp_password);
于 2013-08-02T19:35:18.763 回答