PHP 5.2中是否有与mysqli_fetch_all等效的功能? [英] Is there a functional equivalent to mysqli_fetch_all in PHP 5.2?

查看:60
本文介绍了PHP 5.2中是否有与mysqli_fetch_all等效的功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我在PHP(以及一般而言的后端编程)方面一共是n00b,但我始终不渝地决定要建立一个功能强大的数据库,以便用户可以在客户端搜索我的第一个Web的最终项目.开发人员类.

So, I am a total n00b at PHP (and back-end programming in general), but I never the less decided I wanted to build a functioning database that users could search client-side as th final project for my first web dev class.

无论如何,我在本地主机上创建了站点和数据库,尽管花了一些时间,但我仍使一切正常运行.但是,当我尝试将其移至我的虚拟主机时,一切都开始中断,因为以前我不知道的那个虚拟主机正在使用PHP 5.2.我已经能够使用可疑安全性的一些有效解决方案来操纵其他所有设备(我知道,我知道,但我很绝望,而且这里始终只有伪造数据),但是我无法找到解决办法的一件事对于的是mysqli_fetch_all().我收到未定义函数mysqli_fetch_all()的调用错误.

Anyway, I made my site and database on a localhost, and though it took a while, I got everything functioning perfectly. When I tried to move it to my webhost, however, everything started breaking because, previously unbeknownst to me, the webhost is using PHP 5.2. I've been able to rig everything else with some functioning solutions of dubious security (I know, I know, but I'm desperate, and there's only fake data on here anyway), but the one thing I can't find a fix for is the mysqli_fetch_all(). I get a Call to undefined function mysqli_fetch_all() error.

我将其用于搜索功能:搜索用户时,该函数将具有匹配信息的所有行放入一个数组中,最后将所有结果数组合并为一个返回的数组.我这样做是为了避免忽略未输入的搜索条件,并且不会返回错误(NULL是整个项目存在的祸根).

I'm using it for my search functionality: when you search for a user, the function takes all the rows with matching information and puts it in an array, and at the end, all the result arrays are merged into a single array that is returned. I did it this way so that search criteria that is not entered would be ignored and not return an error (NULL has been the bane of my existence this entire project).

可以在 http://webinfofinal.webatu.com/profiles.html,因此您会看到我正在使用的内容,并且代码在下面.有什么建议?我尝试了其他提取功能,但它们仅返回匹配的第一行.

The site can be viewed at http://webinfofinal.webatu.com/profiles.html so you see what I'm working with and the code is below. Any suggestions? I've tried other fetch functions, but they only return the first matching row.

        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>";
        }

推荐答案

否,仅当您使用

No, the fetch_all method is available only if you use the mysqlnd library.

可以为PHP 5.2编译mysqlnd(请参见

It is possible to compile mysqlnd for PHP 5.2 (see http://blog.ulf-wendel.de/2007/php-compiling-mysqlnd-with-php-525360/) but if your web hosting provider isn't ready to upgrade to a current version of PHP, I doubt they'll install mysqlnd for you.

您可以将代码转换为PDO,它支持 PDOStatement :: fetchAll().

You can convert your code to PDO, which supports PDOStatement::fetchAll().

或者您可以为mysqli编写自己的fetch_all函数,这并不难:

Or you can code your own fetch_all function for mysqli, which is not hard:

function fetch_all($result)
{
   $rows = array(); -- old array syntax still needed in PHP 5.2
   while ($row = $result->fetch_assoc())
          $rows[] = $row;

   return $rows;
}

我建议您找到其他虚拟主机. PHP 5.2正式停产,并且可能在更高版本的PHP中修复了安全漏洞,但在5.2中未修复.参见 http://php.net/eol.php

I recommend you find a different web host. PHP 5.2 is officially end-of-life, and there may be security vulnerabilities that are fixed in later version of PHP, but not in 5.2. See http://php.net/eol.php

这篇关于PHP 5.2中是否有与mysqli_fetch_all等效的功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆