我有與MySQL數據庫的經驗,併成功地連接到他們與幾個項目。無法連接到SQL Server 2008從PHP
現在,我在連接到SQL Server 2008時遇到了問題。工作原理:<?php phpinfo(); ?>
和sqlsrv和pdo_sqlsrv部分顯示在此頁面上。下面是我使用的連接代碼:
<?php
$serverName = "serverName\sqlexpress"; //serverName\instanceName
$connectionInfo = array("Database"=>"dbName", "UID"=>"userName", "PWD"=>"password");
$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));
}
?>
此代碼是直接從php.net這裏:http://www.php.net/manual/en/function.sqlsrv-connect.php。我做的唯一更改是用##。#。#。##替換serverName \ sqlexpress。並更改:dbName,用戶名,密碼。
下面是結果,當我運行的連接上面的代碼:
Parse error: syntax error, unexpected '$serverName' (T_VARIABLE) in C:\inetpub\quote.myWebsite.com\index.php on line 23
即使我像這樣運行一些簡單:
<?php $myVariable = "someString"; ?>
我得到同樣的類型分析錯誤的:
Parse error: syntax error, unexpected '$myVariable' (T_VARIABLE) in C:\inetpub\quote.myWebsite.com\index.php on line 23
爲什麼我在我的PHP代碼中收到錯誤?
這與SQL服務器沒有任何關係,它是純粹的PHP語法錯誤。 –
此代碼中沒有'23'行,你如何使用它?此外,該鏈接似乎包含一個端口號'$ serverName =「serverName \ sqlexpress,1542」; // serverName',你沒有。 –
index.php文件的第23行是什麼? – Robbert