如何使用PHP连接到MS SQL?

时间:2021-11-21 11:50:11

I have a PHP script that uses the following code:

我有一个使用以下代码的PHP脚本:

$con = mssql_connect('192.168.152.2\webservice','sa','p@$$w0rd') or die('Could not connect to database server');     
mssql_select_db('mydatabase') or die('Could not connect to Database');

I need to run this script on 2 machines. One server works ok, another doesnt.

我需要在2台机器上运行此脚本。一台服务器工作正常,另一台服务器不工

Ok, here’s a few things I know/tried:

好的,这是我知道/尝试的一些事情:

  • Both machines already connect to a MSSQL database. They have php5-sybase library installed.
  • 两台机器都已连接到MSSQL数据库。他们安装了php5-sybase库。

  • I’m convinced there aren’t any restrictions to the sa user that is used to connect to both – in terms of hosts it can connect from.
  • 我确信对于用于连接两者的sa用户没有任何限制 - 就它可以连接的主机而言。

Things I don't know how to check/or could influence things:

我不知道如何检查/或可能影响事物的事情:

  • Even though both machines have same php libraries. Do they have same version of library?
  • 即使两台机器都有相同的php库。他们有相同版本的库吗?

  • Number of concurrent connections a MSSQL user can have on the box.
  • MSSQL用户可以在框中拥有的并发连接数。

  • The box that cant connect is running PHP Version 5.2.4 (however can connect to another MS SQL database)
  • 无法连接的框运行PHP版本5.2.4(但可以连接到另一个MS SQL数据库)

I dont know what I'm missing. Any advice much appreciated.

我不知道我错过了什么。任何建议都非常感谢。

2 个解决方案

#1


0  

What about the host IP addresses ? They must be different right ?

主机IP地址怎么样?他们一定不一样吧?

Machine No.1 works since it must be associated with 192.168.152.2 , other machine must have a different ip. So try the IP associated with Machine No.2

机器No.1工作,因为它必须与192.168.152.2相关联,其他机器必须有不同的IP。因此,尝试与机器2相关的IP

#2


0  

Both server have different IP.

两台服务器都有不同的IP。

So try other server host IP.

所以尝试其他服务器主机IP。

Just change the host of new server it will work fine.

只需更改新服务器的主机即可正常工作。

$con = mssql_connect('192.168.152.2\webservice','sa','p@$$w0rd') or die('Could not connect to database server');     
mssql_select_db('mydatabase') or die('Could not connect to Database');

just change 192.168.152.2\webservice to other server host.

只需将192.168.152.2 \ webservice更改为其他服务器主机。

#1


0  

What about the host IP addresses ? They must be different right ?

主机IP地址怎么样?他们一定不一样吧?

Machine No.1 works since it must be associated with 192.168.152.2 , other machine must have a different ip. So try the IP associated with Machine No.2

机器No.1工作,因为它必须与192.168.152.2相关联,其他机器必须有不同的IP。因此,尝试与机器2相关的IP

#2


0  

Both server have different IP.

两台服务器都有不同的IP。

So try other server host IP.

所以尝试其他服务器主机IP。

Just change the host of new server it will work fine.

只需更改新服务器的主机即可正常工作。

$con = mssql_connect('192.168.152.2\webservice','sa','p@$$w0rd') or die('Could not connect to database server');     
mssql_select_db('mydatabase') or die('Could not connect to Database');

just change 192.168.152.2\webservice to other server host.

只需将192.168.152.2 \ webservice更改为其他服务器主机。