2013-08-02 190 views
0

我有Windows和Linux服務器。 SQL Server 2005安裝在Windows機器上,我想使用PHP從我的其他Linux服務器連接到Windows數據庫。服務器位於不同的位置。從Linux連接到SQL Server 2005與PHP

我已經嘗試了一切,但沒有成功。這裏是我的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連接:(

有什麼建議?

回答

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);