Jump to content

Memory Issue with MySqli code


Deepzone

Recommended Posts

I have the following code the lookup data from a database.  It runs okay on my llocal machine but it give me "Fatal error: Allowed memory size of 33554432 bytes exhausted" whenit runs on hosting server.  It indicates fatal error at line of $r[field3]); 

 

I googled the error and found the response for similar situation is to re-code to prevent memory leak.  Can anyone point out how the following can be improve to prevent the error from happening.  Thanks a lot.

 

 

 

 

$stmt = $database_connection->stmt_init();
    if ($stmt->prepare("SELECT keyA, field1, field2, field3 FROM tableA JOIN tableB ON tableA.field1 = tableB.keyB JOIN tableC ON tableA.field2 = tableC.keyC
        WHERE field3 LIKE ?")) {
        
        $stmt->bind_param('s', $likeString);
        $stmt->bind_result($r['keyA'],
            $r['field1'],
            $r['field2'],
            $r['field3']);
        if (!$stmt->execute()) {
             echo "Execute failed: (" . $stmt->errno . ") " . $stmt->error;
            exit();
        }    
        while($stmt->fetch()){    
            foreach( $r as $key=>$value ) {
                $row_tmb[ $key ] = $value;
            }
            $r[] = $row_tmb;
        }

    return $r;

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.