简体   繁体   English

如何从PHP连接到mssql?

[英]How to connect to mssql from php?

I have a dedicated centos server. 我有一个专用的centos服务器。 It needs to be able to connect to a remote windows machine running SQL Server 2012. The provider installed freetds. 它需要能够连接到运行SQL Server 2012的远程Windows计算机。提供程序已安装freetds。 I'm running PHP Version 5.3.28. 我正在运行PHP版本5.3.28。

We can ping the remote ms-sql server from the linux box. 我们可以从linux框中ping远程ms-sql服务器。 But, when I try to run the test command: tsql -S your.server.name -p 1433 -U -P it times out. 但是,当我尝试运行测试命令时:tsql -S your.server.name -p 1433 -U -P会超时。

I tried the sample code I found online to test via php, but as my version is greater than 5.3 the mssql_connect function no longer is functional. 我尝试了在网上找到的示例代码以通过php进行测试,但是由于我的版本大于5.3,因此mssql_connect函数不再起作用。

$conn = mssql_connect("servername", "<user>", "<password>");

I get Call to undefined function mssql_connect()...so, I'll have to use PDO (I think). 我收到了对未定义函数mssql_connect()的调用...因此,我将不得不使用PDO(我认为)。

Anyway, the PDO probably won't work until we get the tsql to work, and it just times out. 无论如何,直到我们使tsql起作用,PDO才可能起作用,并且它只是超时了。

Any ideas? 有任何想法吗?

There are a few comments in the mssql_connect section of the php manual. 在php手册的mssql_connect部分中有一些注释。 Various people having had similar problems with connecting from linux/unix. 从linux / unix进行连接的各种人都有类似的问题。

Maybe there is some insight there: http://www.php.net/manual/en/function.mssql-connect.php 也许那里有一些见识: http : //www.php.net/manual/en/function.mssql-connect.php

Also, as always, make sure you have physical connectivity from the box itsself and from within php. 此外,一如既往,请确保您本身具有与盒以及php内部的物理连接。

First of all be sure that nothing block the port 1433. 首先,请确保没有任何东西阻塞端口1433。

Try to run thd command: 尝试运行thd命令:

telnet yourserver.com 1433 远程登录yourserver.com 1433

If you get enter - try to check configuration of the driver and configuration of mssql server. 如果输入,请尝试检查驱动程序的配置和mssql服务器的配置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM