开发者

Connecting to a MS SQL server from a different machine running PHP

I have a server running MSSQL. Then I have another server running the usual LAMP (php) stack. Is there any easy way to connrect to the MSSQL server from the linux server?

(I don't have details on what 开发者_如何学Cversion of sql server its using at the moment)

thanks


You need to install ODBC for LINUX and FreeDTS.
FreeTDS is a set of libraries for Unix and Linux that allows your programs to natively talk to Microsoft SQL Server and Sybase databases.
http://www.freetds.org/

Try to use 'search' on stackoverflow.com
PHP MS SQL Unix Driver - Microsoft or FreeTDS


To connect to an MSSQL server from a PHP script you can run the mssql_connect() (doc) function. The parameters you'll need for a remote server are, in order:

  1. The hostname of the server you are connecting to.
  2. The username with which you wish to connect.
  3. The password for that username.

All of these parameters are strings. You can then run queries using the mssql_query() (doc) function.

For more information about connecting to MSSQL servers from PHP scripts take a look at the PHP documentation on MSSQL, and the list of PHP function for MSSQL.


Make sure you have the extension mssql.so. Go to php.ini and comment out the extension. As @k102 suggested try connecting using

mssql_connect (string $servername , string $username,  string $password )

For syntax check the link http://php.net/manual/en/function.mssql-connect.php

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜