PHP 无法连接到 MS SQL Express 2008

发布于 2024-09-09 22:11:21 字数 1484 浏览 13 评论 0原文

我正在努力从我的 PHP 文件连接到我的 MS SQL Express 2008 版本,但这似乎几乎不可能。

我找到了一些关于 intarweb 解决问题的指南/注释,但这些都没有进一步帮助我。

我从另一个站点获取了一个脚本并输入了我的数据库信息,但我仍然收到错误:

<?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);
?>

我收到此错误:

警告:mssql_connect() [function.mssql-connect]:无法 连接到服务器: localhost in C:\inetpub\vhosts\dexterholding.dk\httpdocs_rip\sql.php 第 8 行无法连接到 SQL 本地主机上的服务器

您可以在以下位置亲自查看: http://www.dehold.net/_rip/ sql.php

有什么想法吗? 我正在使用 PLESK 和 PHP5 作为 FastCGI 运行 Windows Server 2008。

I'm struggling to connect to my MS SQL Express 2008 edition from my PHP files, but it seems virtually impossible.

I've found several guides/notes on teh intarweb solving the issues, but none of these have helped me any further.

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

You can see for yourself at: http://www.dehold.net/_rip/sql.php

Any ideas?
I'm running Windows Server 2008 with PLESK and PHP5 as FastCGI.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

短叹 2024-09-16 22:11:21

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

With MSSQL, your server name will look like this: machinenameoraddress\serverinstancename
and example would be 192.168.14.201\MSSQLEXPRESS or TESTMACHINE\MYTESTDBSERVER.

你与昨日 2024-09-16 22:11:21

可能是用户帐户没有访问 SQL Server 的权限。

虽然查看您的代码,您使用的是 SQL 身份验证而不是 Windows 身份验证,但大概此帐户是在 SQL Server 中设置的,并且配置为允许 SQL 身份验证?

It could be that the user account does not have permission to access 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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文