2010-06-25 92 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