2

I am getting this error. I make use of a class file, function file and then the view file. Fatal error: Allowed memory exhausted

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

My function looks like this:

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

And lastly my view page looks like this:

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.';
                }

The rest and all the other functions that look for either only the first and last names works fines.

2
  • Looks like your hitting the memory limit, try set ini_set('memory_limit', '500M'); Commented Feb 20, 2013 at 2:41
  • 1
    Sorry found my problem: function adminSearchFullName($admin_firstname,$admin_lastname){ return $adminsearchresultsfullname = contacts::adminSearchFullName($admin_firstname,$admin_lastname); } Commented Feb 20, 2013 at 2:45

1 Answer 1

1

Instead of increasing memory limit you have to reduce amount of data processed by the script. That's what databases are for. Let database to do all the job and then return only data required on the certain page. it is seldom exceeds 100 kilobytes - otherwise the pagge will be too heavy to load by the browser.

However, it seems that your problem was cased by mere recursion by accident and you already solved it.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.