2

我收到这个错误。我使用类文件、函数文件和视图文件。致命错误:允许的内存已耗尽

        public function adminSearchFullName($admin_firstname,$admin_lastname){
        $adminsearchresultsfullname = array();

        try {
            $db = database::databaseConnect();

            $stmt = $db->prepare('SELECT * FROM personalinfo WHERE firstname like ? AND lastname like ? AND deleted = 0');
            $stmt->execute(array('%' . $admin_firstname . '%', '%' . $admin_lastname . '%'));

            $adminsearchresultsfullname = $stmt->fetchAll(PDO::FETCH_OBJ);

            if($stmt->rowCount() < 1){
                $adminsearchresultsfullname = null;
            }
            $db = null;
        }
        catch (PDOException $e){
            $adminsearchresultsfullname = null;
        }
        return $adminsearchresultsfullname;
    }        

我的功能如下所示:

     function adminSearchFullName($admin_firstname,$admin_lastname){
     return $adminsearchresultsfullname = adminSearchFullName($admin_firstname,$admin_lastname);
 }

最后我的视图页面如下所示:

if(!empty ($admin_firstname) && !empty($admin_lastname)){
                    //Query and display contact details based on first and last names.

                    $adminsearchresultsfullname = adminSearchFullName($admin_firstname,$admin_lastname);
                    if ($adminsearchresultsfullname != null){
                        ?>
                        <a href="index.php">Home</a> | <a href="adduser.php">Add User</a> | <a href="viewusers.php">View Users</a> |<a href="addcontact.php">Add Contact</a> | <a href="viewcontacts.php">View Contacts</a> | <a href="searchcontact.php">Search Contact</a><br /><hr />
                        <p>Click on the name to see details of the contact.</p>

                        <table cellpadding="5">
                            <tr>
                                <td>
                                    <b>Search result</b>
                                </td>
                            </tr>

                        <?php

                        foreach($adminsearchresultsfullname as $key => $adminfoundfullname){
                            $admin_id_fullname = $adminfoundfullname->id;
                            $admin_found_fullname_firstname = $adminfoundfullname->firstname;
                            $admin_found_fullname_lastname = $adminfoundfullname->lastname;
                            ?>
                            <tr>
                                <td>
                                    <a href="contactdetails.php?id=<?php echo $admin_id_fullname; ?>"><?php echo $admin_found_fullname_firstname . ' ' . $admin_found_fullname_lastname; ?></a>
                                </td>
                            </tr>
                        <?php 
                        }?>
                        </table>
                    <?php }

                }else{
                    echo 'No record found.  Please <a href="searchcontact.php"> return</a> and try a different name.';
                }

其余的以及仅查找名字和姓氏的所有其他功能都可以正常工作。

4

1 回答 1

1

您必须减少脚本处理的数据量,而不是增加内存限制。这就是数据库的用途。让数据库完成所有工作,然后只返回特定页面所需的数据。它很少超过 100 KB - 否则页面将太重而无法被浏览器加载。

但是,您的问题似乎只是偶然的递归,而您已经解决了。

于 2013-02-20T04:37:49.407 回答