我收到此错误致命错误:当我尝试从MYSQL检索数据并显示到此行时调用此行上的布尔值上的成员函数RecordCount()if($ results-> RecordCount()> 0)一张桌子。我尝试了很多解决方案,但它仍然得到了错误。下面是我的PHP代码
if (!$conn)
{
die("Failed to connect to database : " . $dsn);
}
else
{
//database connection ok
ADOdb_Active_Record::SetDatabaseAdapter($conn);
if($category=='4')
{
$query= $conn->prepare("SELECT * FROM profiles");
$results=$conn->Execute($query);
}
else if ($category=='3')
{
$query= $conn->prepare("SELECT * FROM profiles WHERE biography LIKE ?");
$results=$conn->Execute($query);
}
else if ($category=='2')
{
$query= $conn->prepare("SELECT * FROM profiles WHERE ranks = ?");
$results=$conn->Execute($query);
}
else if ($category=='1')
{
$query= $conn->prepare("SELECT * FROM profiles WHERE nationality LIKE ?");
$results=$conn->Execute($query);
}
else
{
}
if($results->RecordCount()>0)
{
while(!$results->EOF)
{
//if($results->RecordCount()>0)
//{
echo "<table border='1' cellpadding='5'>"
. "<tr><th>Name</th><th>Nationality</th><th>Current Score</th><th>Current Standings</th><th>Event Participate</th><th>Team</th><th>Bike</th><th>Picture</th>";
echo "<tr><td>".$results->fields[1]."</td><td>".$results->fields[2]."</td><td>".$results->fields[3]."</td> <td>".$results->fields[4]."</td>
<td>".$results->fields[5]."</td> <td>".$results->fields[6]."</td> <td>".$results->fields[7]."</td> <td>><img src='loadimage.php?id=".$results->fields[0]."' height='100' /></td></tr>";
echo "</table><br/>";
$results->MoveNext();
}
}
else
{
echo "There is no match record. <br/><br/>";
}
}
$results->close();
}
答案 0 :(得分:0)
您的错误是由$ results为false引起的。这意味着查询失败了,可能是因为您似乎没有提供参数来替换&#34;?&#34;在您的查询中。
您可以使用
检查数据库错误$conn->ErrorMsg()
当$ results === false
时