2014-12-03 73 views
0

交易全部, 我有以下問題:我想用php函數連接到ms sqlserver2008。 在過去,它可以正常使用mssql_connect。 因爲我已經更新到PHP 5.3我有一個數組的問題:PHP 5.3和sqlsrv_connect

語法:

$serverName = "sql server"; //serverName\instanceName, portNumber (default is 1433) 
$connectionInfo = array("db", "user", "pw"); 
$conn = sqlsrv_connect($serverName, $connectionInfo); 

if($conn) { 
echo "Connection established.<br />"; 
}else{ 
echo "Connection could not be established.<br />"; 
die(print_r(sqlsrv_errors(), true)); 
} 
exit; 

當我將顯示頁面,我得到這個數組錯誤:

Connection could not be established. 
Array ([0] => Array ([0] => IMSSP [SQLSTATE] => IMSSP [1] => -8 [code] => -8 [2] => An 
invalid connection option key type was received. Option key types must be strings. 
[message] => An invalid connection option key type was received. Option key types must be strings.)) 

也許有人有一個主意 ?對此,我將非常感謝

回答

0

檢查MANUAL。該connectionInfo應該是一個鍵/值對數組:

$connectionInfo = array("Database"=>"dbName", "UID"=>"userName", "PWD"=>"password"); 
0

我認爲這是數組定義,試試這個:

$connectionInfo = array("Database"=>"db", "UID"=>"user", "PWD"=>"pw");