1

I have this query:

$start = 0;
$number_of_posts = 10;

 $sql = $db -> prepare("
            SELECT  U.username, U.offer_photo, F.activities, A.id_offer, A.offer, A.role, A.content, A.date_post, A.limit, B.type_offer, C.local  
            FROM  type_offer B, local C, offer A
            INNER JOIN users U
            ON U.id_user = A.company_users_id_user1
            INNER JOIN company F
            ON F.users_id_user = A.company_users_id_user1   
            WHERE state = 0 
            AND
            A.type_offer_id_type_offer = B.id_type_offer 
            AND
            A.local_id_local = C.id_local
            ORDER BY date_post 
            DESC LIMIT ?, ?
            ");
        $sql -> bind_param('ii',$start, $number_of_posts);
        $sql -> execute();
        $sql -> bind_result($username, $offer_photo, $actividades, $id_oferta, $oferta, $cargo, $conteudo, $data_post, $data_limite, $tipo_oferta, $local); //problem here
            $sql->fetch();
            $sql-close;

And i have memory_limit: 256M in phpinfo(); However i still getting a problem with the memory. I already tried this code without success :

set_time_limit(0);
ini_set('memory_limit', '2000M');

So my question is, the query can be optimized, or how can i increase the memory ? I don't have access to php.ini, but i think 256MB should be enough, so maybe the problem is the query.

user947462
  • 929
  • 6
  • 18
  • 28
  • That error is not the one you get when `memory_limit` is reached. It seems that your PHP interpreter is actually crashing due to memory problems. Does the SQL query perform well when run from a regular MySQL client? – Álvaro González Jan 11 '12 at 16:42
  • Yes, the query works well in phpMyAdmin. And the most strange i have a local server with memory limit 128MB and i don't have any issue. – user947462 Jan 11 '12 at 16:49

1 Answers1

1

Is the u.offer_photo a blob field? If so I'd suggest rewriting the logic so you don't fetch the blob data until you actually display it.

Even if you can get around the memory limit by increasing the allocation it's both anti-social to use excessive memory and brittle in that an increase in your database size in the future will likely break the system.

Cruachan
  • 15,733
  • 5
  • 59
  • 112