我想我的PHP網頁與我的MS SQL數據庫的連接。我從互聯網上得到了這些代碼,但已經嘗試了其他代碼。所有似乎都回來了與「mssql_connect」的問題。PHP連接MS SQL
我已經試過(我認爲)的一切並不能找出爲什麼它不會工作。
我的代碼是:
<?php
$myServer = 'SQL5008.Smarterasp.net,1433';
$myUser = '*****';
$myPass = '*****';
$myDB = '*****';
//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 ";
$query .= "FROM tblEmployees ";
$query .= "WHERE CompanyID=3";
//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);
?>
嘗試刪除單引號$數據庫句柄= mssql_connect($ myServer上,$爲myuser,$爲mypass) –
對不起,我曾試圖把連接字符串中的文本。我將編輯我的代碼並將其刪除。仍然沒有運氣。 –