Jason
Jason

Reputation: 63

Possible Memory Leak with prepared statements?

Background:

I am trying to learn prepared statements, and this one is throwing an error I would like to learn how to fix.

The data in the Item table is inputted by users which is why I am using a prepared statement for this one as well, and well... the practice of course..

I spent about an hour searching this site, and most sites are recommending changing the memory limit to a higher value.. I don't think this would be required, as the table I am selecting has very few rows..

Purpose of query:

The user loads the page, and it will list out the items. From here they can purchase said items with points they acquire from participating in a program we run.. This is the query to list the items..

Here is the Error:

Fatal error: Allowed memory size of 201326592 bytes exhausted (tried to allocate 4294967296 bytes) in (Removed, but is location of file) on line 80

Line 80:

$Select_stmt2->bind_result($Item_Key, $Item_Image, $Item_Name, $Item_Amount, $Item_Describe);

Extra Information:

Also the $conn variable is pulled from a second configure.php file during the header. I will display it minus the info to connect to the server.

//Connect to Database
$conn = new mysqli('localhost', 'Username', 'Password', 'Table Name');

Code:

//Item Points
            $Enabled = 'Enabled';

            $Select_Query2 = "SELECT Item_Key, Item_Image, Item_Name, Item_Amount, Item_Describe FROM Item WHERE Item_Status = ?";
            $Select_stmt2 = $conn->prepare($Select_Query2);
            $Select_stmt2->bind_param('s',$Enabled);
            $Select_stmt2->execute();

            $Select_stmt2->bind_result($Item_Key, $Item_Image, $Item_Name, $Item_Amount, $Item_Describe);
            if(!$Select_stmt2)
            {
                echo'Error: Selecting Items';
            }
            else
            {
                /* Code to display the data for line 80 on the website */
            }

Upvotes: 3

Views: 595

Answers (1)

Tim3880
Tim3880

Reputation: 2583

Do you have blob column? The number 4294967296 indicates you are trying allocate memory for max length of blob column. It can be a bug but not a leak, and the culprit could be the bind statement. If you have a blob column and it keep giving error, try cast it a varchar in your select statement.

Upvotes: 1

Related Questions