Php 致命错误:在布尔值上调用成员函数free()
我的服务器上的数据库出现错误。在我本地的电脑上一切都很好。我已通过主机确认数据在服务器上,并且查询正常,但我一直收到以下错误消息: 致命错误:在布尔值上调用成员函数free() 我的php代码正在同一数据库中的另一个表上成功运行。我已经在phpMyAdmin上测试了这个查询,它可以处理数据。但是当我测试Php 致命错误:在布尔值上调用成员函数free(),php,mysql,mysqli,Php,Mysql,Mysqli,我的服务器上的数据库出现错误。在我本地的电脑上一切都很好。我已通过主机确认数据在服务器上,并且查询正常,但我一直收到以下错误消息: 致命错误:在布尔值上调用成员函数free() 我的php代码正在同一数据库中的另一个表上成功运行。我已经在phpMyAdmin上测试了这个查询,它可以处理数据。但是当我测试$result时,结果仍然是错误的。我不明白为什么。以下是我的php代码: <?php // Connect to the database by creating a new m
$result
时,结果仍然是错误的。我不明白为什么。以下是我的php代码:
<?php
// Connect to the database by creating a new mysqli object
include "inc/DBconnect.php";
// Run a query and put the result into a new variable named $result -- It's just a table of results
$result = $mysql->query("
SELECT
staffId,
company,
fName,
lName,
title,
contact1,
contact2,
department,
comments,
lastEdit
FROM staff WHERE archive = 0 ORDER BY lName");
// Loop through the result from 0 to the number of rows in the result, one row at a time. $i will contain
// the current row number every pass through the loop ( you could do it backwards too but why? )
for ($i = 0; $i < $result->num_rows; $i++) {
// Move to row number $i in the result set.
$result->data_seek($i);
// Get all the columns for the current row as an associative array -- we named it $aRow
$aRow = $result->fetch_assoc();
$staffId = $aRow['staffId'];
// Write a table row to the output containing information from the current database row.
print "<p>";
print "<staffName><a href='staffDetails.php?ID=$staffId'>" . $aRow['fName'] . " " . $aRow['lName'] . "</a> (" . $aRow['staffId'] . ")</staffName>";
print "<title>" . $aRow['title'] . "</title>";
print "<contact>" . $aRow['contact1'] . " | " . $aRow['contact2'] . "</contact>";
print "<company>" . $aRow['company'] . "</company>";
print "<department>" . $aRow['department'] . "</department>";
print "</p>";
}
// Very important: Close your result set to free up the memory it's taking.
$result->free()
?>
您应该改用while循环:
if ($result = $mysql->query($query)) {
while ($aRow = $result->fetch_assoc()) {
$staffId = $aRow['staffId'];
print "<p>";
print "<staffName><a href='staffDetails.php?ID=$staffId'>" . $aRow['fName'] . " " . $aRow['lName'] . "</a> (" . $aRow['staffId'] . ")</staffName>";
print "<title>" . $aRow['title'] . "</title>";
print "<contact>" . $aRow['contact1'] . " | " . $aRow['contact2'] . "</contact>";
print "<company>" . $aRow['company'] . "</company>";
print "<department>" . $aRow['department'] . "</department>";
print "</p>";
}
}else{
printf("Errormessage: %s\n", $mysql->error);
}
你要我看的帖子说查询失败了。但是我已经在phpMyAdmin上直接尝试了这个查询,它可以正常工作。这就消除了错误。但没有打印任何数据。我已经在phpMyAdmin上测试了该查询,它运行正常,但$result仍然为False。@AbigailHardin如果返回False,则需要打印错误,请参阅我的编辑谢谢。我没有得到任何结果,但它只是打印错误消息:。没有mysql错误,也可以添加mysqli_报告(mysqli_报告错误| mysqli_报告严格)代码>就在连接箱之前!这不仅修复了它,还向我展示了一些新的方法,我可以检查未来的错误。非常感谢。
$mysql = new mysqli("xxxxx", "xxx", "xxx", "xxx");
if ($mysql->connect_errno) {
printf("Connect failed: %s\n", $mysql->connect_error);
exit();
}
$query = "...";
if ($result = $mysql->query($query)) {
while ($aRow = $result->fetch_assoc()) {
$staffId = $aRow['staffId'];
print "<p>";
print "<staffName><a href='staffDetails.php?ID=$staffId'>" . $aRow['fName'] . " " . $aRow['lName'] . "</a> (" . $aRow['staffId'] . ")</staffName>";
print "<title>" . $aRow['title'] . "</title>";
print "<contact>" . $aRow['contact1'] . " | " . $aRow['contact2'] . "</contact>";
print "<company>" . $aRow['company'] . "</company>";
print "<department>" . $aRow['department'] . "</department>";
print "</p>";
}
}else{
printf("Errormessage: %s\n", $mysql->error);
}
$mysqli->close();