【发布时间】:2014-10-10 18:53:17
【问题描述】:
所以,我在 PHP(以及一般的后端编程)方面完全是 n00b,但我从来没有决定要构建一个功能齐全的数据库,用户可以搜索客户端作为我的第一个 Web 的最终项目开发类。
无论如何,我在 localhost 上创建了我的网站和数据库,虽然花了一些时间,但我让一切正常运行。但是,当我尝试将其移至我的虚拟主机时,一切都开始崩溃,因为以前我不知道,该虚拟主机使用的是 PHP 5.2。我已经能够用一些可疑的安全解决方案来操纵其他所有东西(我知道,我知道,但我很绝望,无论如何这里只有假数据),但我找不到修复的一件事因为是 mysqli_fetch_all()。我收到一个 Call to undefined function mysqli_fetch_all() 错误。
我将它用于我的搜索功能:当您搜索用户时,该函数获取所有具有匹配信息的行并将其放入一个数组中,最后,所有结果数组合并为一个返回的数组。我这样做是为了忽略未输入的搜索条件并且不返回错误(NULL 一直是我在整个项目中存在的祸根)。
可以在http://webinfofinal.webatu.com/profiles.html 上查看该站点,因此您可以看到我正在使用的内容,代码如下。有什么建议?我尝试了其他 fetch 函数,但它们只返回第一个匹配的行。
if ($firstName != null){
$result2 = mysqli_query($con, "SELECT displayName , firstName , lastName , eMail , age , classification , major , faveAnimes FROM a2097702_fac.members where firstName = '$firstName' ");
$query2 = mysqli_fetch_all($result2,MYSQLI_ASSOC);
$search = array_merge_recursive($search, $query2);
}
if ($lastName != null){
$result3 = mysqli_query($con, "SELECT displayName , firstName , lastName , eMail , age , classification , major , faveAnimes FROM a2097702_fac.members where lastName = '$lastName' ");
$query3 = mysqli_fetch_all($result3,MYSQLI_ASSOC);
$search = array_merge_recursive($search, $query3);
}
if ($eMail != null){
$result4 = mysqli_query($con, "SELECT displayName , firstName , lastName , eMail , age , classification , major , faveAnimes FROM a2097702_fac.members where eMail = '$eMail' ");
$query4 = mysqli_fetch_all($result4,MYSQLI_ASSOC);
$search = array_merge_recursive($search, $query4);
}
if ($age != null){
$result5 = mysqli_query($con, "SELECT displayName , firstName , lastName , eMail , age , classification , major , faveAnimes FROM a2097702_fac.members where age = '$age' ");
$query5 = mysqli_fetch_all($result5,MYSQLI_ASSOC);
$search = array_merge_recursive($search, $query5);
}
if ($classification != null){
$result6 = mysqli_query($con, "SELECT displayName , firstName , lastName , eMail , age , classification , major , faveAnimes FROM a2097702_fac.members where classification = '$classification' ");
$query6 = mysqli_fetch_all($result6,MYSQLI_ASSOC);
$search = array_merge_recursive($search, $query6);
}
if ($major != null){
$result7 = mysqli_query($con, "SELECT displayName , firstName , lastName , eMail , age , classification , major , faveAnimes FROM a2097702_fac.members where major = '$major' ");
$query7 = mysqli_fetch_all($result7,MYSQLI_ASSOC);
$search = array_merge_recursive($search, $query7);
}
if ($faveAnimes != null){
$result8 = mysqli_query($con, "SELECT displayName , firstName , lastName , eMail , age , classification , major , faveAnimes FROM a2097702_fac.members where faveAnimes = '$faveAnimes' ");
$query8 = mysqli_fetch_all($result8,MYSQLI_ASSOC);
$search = array_merge_recursive($search, $query8);
}
if ($search != null){
echo "<html>";
echo "<head>";
echo"<title> Anime Club Search Results | Web Info Final Project </title>";
echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"webinfofinal.css\">";
echo "</head>";
echo "<div class=\"content\" style=\"width:50%; margin-left:-20%;\">";
echo "<div class=\"header\">";
echo "<p></p><p>Your search results are below. </p>";
echo "</div>";
echo "<pre>";
print_r($search);
echo "</pre>";
echo "<p>End of results. <a href=\"profiles.html\">Search again?</a></p>";
echo "<a href=\"login.html\"><input type='button' value='Update My Profile' id='updateProfile'></a>";
echo "<a href=\"logout.php\"><input type='button' value='Log Out' id='logout'></a>";
echo "</div>";
echo "</html>";
}
【问题讨论】:
标签: php mysqli undefined php-5.2