我是 PHP 新手,所以我为我的无知道歉。我试图将 PHP 连接到我计算机上的 SQL Server 数据库。我希望表格显示在网页上,所以这是早期的测试和学习。我的代码是
<!DOCTYPE html>
<html>
<head>
<title>Test</title>
</head>
<body>
<table border="5" bgcolor="white" width="300" align="center">
<tr>
<th bgcolor="grey">InputType</th>
<th bgcolor="">Valid</th>
</tr>
<?php
$myServer = "localhost";
$myUser = "xxxxx";
$myPass = "xxxx";
$myDB = "xxxxxxxxx";
//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 inputtype, valid FROM dbo.eqinputs";
//Execute the SQL query and return records
$result = mssql_query($query)
or die('A error occured: ' . mysql_error());
//Show result
while ( $rows = mssql_fetch_array($result) )
{
$InputType=$rows['InputType'];
$Valid=$rows['Valid'];
echo "<tr>
<td>$InputType</td>
<td>$Valid</td>
</tr>";
}
?>
</table>
</body>
</html>
当我这样做并保存为 .php 时,结果如下
如您所见,代码本身以及与我的数据库的连接都存在错误。任何帮助将不胜感激