2013-02-20 67 views
2

我收到此錯誤。我使用了一個類文件,函數文件,然後是視圖文件。致命錯誤:讓內存耗盡PHP OOP PDO致命錯誤:允許的內存耗盡

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

的休息和所有其他職能要麼只是名字和姓氏工作罰款。

+0

看起來像你的內存限制,嘗試設置ini_set('memory_limit','500M'); – shapeshifter 2013-02-20 02:41:59

+1

對不起,發現我的問題: function adminSearchFullName($ admin_firstname,$ admin_lastname){ return $ adminsearchresultsfullname = contacts :: adminSearchFullName($ admin_firstname,$ admin_lastname); } – Willem 2013-02-20 02:45:09

回答

1

不必增加內存限制,而必須減少腳本處理的數據量。這就是數據庫的用途。讓數據庫完成所有工作,然後僅返回特定頁面上所需的數據。它很少超過100千字節 - 否則瀏覽器將無法加載頁面。

但是,您的問題似乎是偶然發生的遞歸,您已經解決了這個問題。

相關問題