简体   繁体   English

MSSQL,PHP连接问题,正在访问数据库

[英]MSSQL , PHP Connection issues, accessing a database

I am trying to connect to a database for a client (I'm a student), the website is using drupal and connects to their live stock with a module called SPNET, the MSSQL connection details are as follows: 我正在尝试连接到客户端的数据库(我是一名学生),该网站正在使用drupal并使用名为SPNET的模块连接到其牲畜,MSSQL连接详细信息如下:

localhost,1433
database: techtech
username: tech1
password: EXAMPLEPASSWORD

that works fine, but now im trying to connect to the same database with PHP, as follows: 可以正常工作,但是现在我尝试使用PHP连接到同一数据库,如下所示:

<?php
$host = "localhost:1433";
$userDB = "tech1";
$passwordDB = "EXAMPLEPASSWORD";

$database = "techtech";
$link = mssql_connect($host, $userDB, $passwordDB);

if (!$link) {
die('Something went wrong while connecting to MSSQL');
}
?>

I am given this error: 我收到此错误:

Warning: mssql_connect() [function.mssql-connect]: Unable to connect to server: localhost:1433

I am not sure how to fix this problem, this .php file is located on the same server as drupal is connecting. 我不确定如何解决此问题,此.php文件与drupal连接时位于同一服务器上。

Thanks for the help. 谢谢您的帮助。

Since 1433 is the standard port for MSSQL, you don't have to specify it when connecting with mssql_connect() . 由于1433是MSSQL的标准端口,因此在与mssql_connect()连接时mssql_connect()指定它。 If you want to specify a different port, you need to use this format: 如果要指定其他端口,则需要使用以下格式:

 $host = "localhost,1433";

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

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