简体   繁体   English

PHP无法连接到MS SQL Express 2008

[英]PHP Can't Connect to MS SQL Express 2008

I'm struggling to connect to my MS SQL Express 2008 edition from my PHP files, but it seems virtually impossible. 我正在努力从我的PHP文件连接到我的MS SQL Express 2008版本,但实际上几乎是不可能的。

I've found several guides/notes on teh intarweb solving the issues, but none of these have helped me any further. 我找到了一些有关Intarweb解决问题的指南/说明,但是这些指南/说明都没有进一步帮助我。

I've taken a script from another site and entered my database information, but I still get errors: 我从另一个站点获取了脚本并输入了数据库信息,但是仍然出现错误:

<?php
$myServer = "localhost";
$myUser = "demo_basic";
$myPass = "1234";
$myDB = "demo_basic"; 

//connection to the database
$dbhandle = mssql_connect($myServer, $myUser, $myPass)
  or die("Couldn't connect to SQL Server on $myServer"); 

//select a database to work with
$selected = mssql_select_db($myDB, $dbhandle)
  or die("Couldn't open database $myDB"); 

//declare the SQL statement that will query the database
$query = "SELECT nitid, nisname ";
$query .= "FROM navitems";

//execute the SQL query and return records
$result = mssql_query($query);

$numRows = mssql_num_rows($result); 
echo "<h1>" . $numRows . " Row" . ($numRows == 1 ? "" : "s") . " Returned </h1>"; 

//display the results 
while($row = mssql_fetch_array($result))
{
  echo "<li>" . $row["nitid"] . $row["nisname"] . "</li>";
}
//close the connection
mssql_close($dbhandle);
?>

I get this error: 我收到此错误:

Warning: mssql_connect() [function.mssql-connect]: Unable to connect to server: localhost in C:\\inetpub\\vhosts\\dexterholding.dk\\httpdocs_rip\\sql.php on line 8 Couldn't connect to SQL Server on localhost 警告:mssql_connect()[function.mssql-connect]:无法连接到服务器:第8行的C:\\ inetpub \\ vhosts \\ dexterholding.dk \\ httpdocs_rip \\ sql.php中的localhost无法连接到localhost上的SQL Server

You can see for yourself at: http://www.dehold.net/_rip/sql.php 您可以在以下位置亲自查看: http : //www.dehold.net/_rip/sql.php

Any ideas? 有任何想法吗? I'm running Windows Server 2008 with PLESK and PHP5 as FastCGI. 我正在运行Windows Server 2008和PLESK和PHP5作为FastCGI。

I found this guide which actually made it work for me: 我发现该指南实际上使它对我有用:

http://samsami2u.wordpress.com/2008/06/30/how-to-connect-mssql-with-php/ http://samsami2u.wordpress.com/2008/06/30/how-to-connect-mssql-with-php/

使用MSSQL,您的服务器名称将如下所示: machinenameoraddress\\serverinstancename ,示例为192.168.14.201\\MSSQLEXPRESSTESTMACHINE\\MYTESTDBSERVER

It could be that the user account does not have permission to access SQL Server. 该用户帐户可能没有访问SQL Server的权限。

Although looking at your code you are using SQL auth and not Windows authentication, presumably this account is set up in SQL Server and it is configured to allow SQL Auth? 尽管查看您的代码时使用的是SQL身份验证,而不是Windows身份验证,但是大概该帐户是在SQL Server中设置的,并且配置为允许SQL身份验证?

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

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