2010-06-25 102 views
0

我需要做的是能够使用php脚本连接到sql server 2008数据库上的sql数据库。该脚本在与sql服务器相同的服务器上的IIS 6上运行。我使用PHP 5.3.2和命令sqlsrv_connect来连接。我通过这个方法传递一个用户名,密码,数据库和服务器来连接。但是,当我做我得到错误“登录失败的用户.......”我不知道如果SQL Server 2008设置正确或不接受像这样的连接。sql server 2008登录使用php

我有IIS使用匿名连接,因为php脚本有一个用户名密码被传递到脚本。我需要能够使用这些值来确认sql服务器的登录。

实际的错误:

Array ( 
     [0] => Array ( 
      [0] => 28000 [SQLSTATE] => 28000 
      [1] => 18456 [code] => 18456 
      [2] => [Microsoft][SQL Server Native Client 10.0][SQL Server]Login failed for user 'ecriss'. 
      [message] => [Microsoft][SQL Server Native Client 10.0][SQL Server]Login failed for user '..........'. 
     ) 
     [1] => Array ( 
      [0] => 28000 [SQLSTATE] => 28000 
      [1] => 18456 [code] => 18456 
      [2] => [Microsoft][SQL Server Native Client 10.0][SQL Server]Login failed for user '...........'. 
      [message] => [Microsoft][SQL Server Native Client 10.0][SQL Server]Login failed for user '..........'. 
     ) 
    ) 

感谢您的帮助

回答

0

您的密码看起来是不正确的,你检查该用户是否存在,密码是否有效? MSSQL扩展是否可用,你检查过phpinfo()吗?

尝试conncting像这样(http://www.webcheatsheet.com/php/connect_mssql_database.php

<?php 
$myServer = "localhost"; 
$myUser = "your_name"; 
$myPass = "your_password"; 
$myDB = "examples"; 

//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 id, name, year "; 
$query .= "FROM cars "; 
$query .= "WHERE name='BMW'"; 

//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["id"] . $row["name"] . $row["year"] . "</li>"; 
} 
//close the connection 
mssql_close($dbhandle); 
?> 
+0

,我用我的版本 – 2010-06-25 19:12:03

+0

@E PHP 5.3.2所以mssql_connect不工作。 Criss是什么让你觉得呢? (http://php.net/manual/en/function.mssql-connect.php) - 我也更新了主帖 – LiamB 2010-06-25 19:20:07

+0

根据PHP手册,参考MSSQL扩展:“此扩展不再可用Windows与PHP 5.3或更高版本“。 – 2010-06-25 19:27:58