我已经成功创建了与MSSQL数据库的连接,执行了查询并使用mssql_num_rows返回结果。我能够让$numRows
回显并在页面上显示“返回的行数”。
表中的列具有以下名称:employeeName,prideSelect,prideComment,flagpoleSelect,flagpoleComment。全部是nvarchar(50)或nvarchar(max)
我无法做的是回显表格中的任何数据。我是php / sql的新手,我尝试过寻找没有运气的解决方案。我不确定它是否与设置为nvarchar的数据库列有关。或者如果我的代码中有错误。我已经尝试mssql_fetch_array
和mssql_fetch_row
来显示结果,但无法继续工作。以下是我正在使用的代码:
<?php
//connects to Heros database
$conn = mssql_connect($host, $uid, $pwd) or die('Could not connect')
or die("Couldn't connect to SQL Server on $host");
$selected = mssql_select_db($db, $conn)
or die("Couldn't open database $db");
echo "MSSQL Connection successful";
//declare the SQL statement that will query the database
$query = mssql_query('SELECT * FROM [Heros].[dbo].[tblHeros]');
//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["employeeName"] . $row["prideSelect"] . $row["prideComment"] . "</li>";
}
//close the connection
mssql_close($conn);
?>
答案 0 :(得分:1)
答案 1 :(得分:0)
您写道:$query = mssql_query('SELECT * FROM [Heros].[dbo].[tblHeros]');
代替:$query = 'SELECT * FROM [Heros].[dbo].[tblHeros]';