2014-01-18 239 views
-2

我的WAMP服务器安装在我的系统中。 我也在同一个系统上安装了MS SQL Server 2008。php-mssql服务器数据库连接使用wamp服务器

我想使我的php应用程序与MS SQL Server的连接。 我已经在我的config.php文件中尝试了下面的代码段以获得数据库的一致性。


<?php 

$conn=mssql_connect('localhost','DINKDEV2\Administrator','[email protected]') or die('not connect'); 
mssql_select_db('nevis_pharma_company'); 
if($conn) { 
    echo "Connection established.<br />"; 
}else{ 
    echo "Connection could not be established.<br />"; 
    die(print_r(sqlsrv_errors(), true)); 
} 
?> 
+0

你甚至检查文档? http://www.php.net/manual/en/function.sqlsrv-connect.php – jycr753

回答

0

mssql_connect语法

mssql_connect('servername','username','password',bool); 

所以你必须,而不是指定localhost的MSSQL服务器名。

您也可以尝试PDO

$conn = new PDO("sqlsrv:Server=hostname,port;Database=dbName", "Username", "Password"); 
+0

为什么会这个工作而不是'mssql_connect'? – jycr753

+0

是的,如果PDO驱动程序存在 –

+0

是的,但它可以在'SQL'服务器上工作吗?由于PHP使用'mssql_connect'来处理这个问题,所以即时猜测你已经尝试了这个? – jycr753

0

尝试使用.\SQLEXPRESS代替localhost

$conn=mssql_connect('.\SQLEXPRESS','DINKDEV2\Administrator','[email protected]') or die('not connect'); 
0

试试这个

$conn = mssql_connect( "servername", "DINKDEV2\Administrator", "[email protected]") 
     or die("not connect") 
+0

当我运行该应用程序,它给了我下面的错误信息。 ---------------------------------------------- ( !)致命错误:调用第7行的C:\ wamp \ www \ nevis_pharma \ company \ config.php中的未定义函数mssql_connect() 调用堆栈 #时间内存函数位置 1 0.0010 145496 {main}().. \ index.php:0 2 0.0020 147928 include('C:\ wamp \ www \ nevis_pharma \ company \ config.php').. \ index.php:2 ----------- ------------------------------------- 调查问题并尽快解决。 – user455966