我收到以下错误:The active result for the query contains no fields
以下是我的代码
<?php
session_start();
include 'dbconnect_three.php';
include 'dbconnect.php';
include 'dbconnect_two.php';
$uname = $_SESSION['user'];
$email = $_SESSION['email'];
$message_id = $_POST['mess_id'];
$maxseq = $_POST['maxseq'];
$otheruser = $_POST['otheruser'];
//The part below is the one that does the query to retrieve the messages from the database
$sql_message_retriver = "SELECT message FROM inbox WHERE message_id='$message_id' ";
$sql_message_retriever_result = sqlsrv_query($conn_three, $sql_message_retriever);
while ($sql_message_result_display = SQLSRV_FETCH_ARRAY($sql_message_retriever_result, SQLSRV_FETCH_ASSOC)) {
$message_string = $sql_message_result_display['message'];
echo "<right>$message_string</right>";
}
$seen = 2;
$maxseq = $maxseq + 1;
echo "<form action=// method=post>";
echo "Messageinput type=text name=update>";
echo "<input type=hidden name=message_id value=$message_id>"; // gotta fix this part
echo "<input type=hidden name=maxseq value=$maxseq>";
echo "<input type=hidden name=otheruser value=$otheruser>";
echo "<input type=hidden name=otheremail value=$otheremail>";
echo "<input type=hidden name=keyes value=$keyes>";
echo "<input type=submit name=submit value=Reply>";
echo "</form>";
print_r(sqlsrv_errors());
?>
我得到的确切错误:
Array (
[0] => Array (
[0] => IMSSP
[SQLSTATE] => IMSSP
[1] => -28
[code] => -28
[2] => The active result for the query contains no fields.
[message] => The active result for the query contains no fields.
)
)
以下是我发现从其他论坛解决问题的一个建议:使用sqlsrv_next_result
。我使用它,它说ODBC函数序列错误(类似的东西)。
当我更改我的sql语句时,请注意以下内容:
$sql_id_two="SELECT message
FROM inbox
WHERE message_id = '$message_id'
AND to_email = '$email'
OR from_email = '$email'";
它实际上有效并显示消息。这很奇怪。
任何人都可以解释此错误消息吗?
答案 0 :(得分:0)
我发现什么是错的,我的sql语句出现了拼写错误。所以我为sqlsrv_query插入了错误的资源2拼写。我怎么能这么傻。
答案 1 :(得分:0)
在我的情况下,using PDO,我不得不拨打nextRowset(),因为我试图在insert
之前阅读select
的结果中的列。
SQLSRV equivalent是:
mixed sqlsrv_next_result ( resource $stmt )