Commit c9428d45 authored by Alexander Butenko's avatar Alexander Butenko

fix for out of memory bug

parent 1a7a9c1d
...@@ -769,6 +769,9 @@ class MysqliDb ...@@ -769,6 +769,9 @@ class MysqliDb
{ {
$parameters = array(); $parameters = array();
$results = array(); $results = array();
// See http://php.net/manual/en/mysqli-result.fetch-fields.php
$mysqlLongType = 252;
$shouldStoreResult = false;
$meta = $stmt->result_metadata(); $meta = $stmt->result_metadata();
...@@ -780,13 +783,17 @@ class MysqliDb ...@@ -780,13 +783,17 @@ class MysqliDb
$row = array(); $row = array();
while ($field = $meta->fetch_field()) { while ($field = $meta->fetch_field()) {
if ($field->type == $mysqlLongType)
$shouldStoreResult = true;
$row[$field->name] = null; $row[$field->name] = null;
$parameters[] = & $row[$field->name]; $parameters[] = & $row[$field->name];
} }
// avoid out of memory bug in php 5.2 and 5.3 // avoid out of memory bug in php 5.2 and 5.3. Mysqli allocates lot of memory for long*
// and blob* types. So to avoid out of memory issues store_result is used
// https://github.com/joshcam/PHP-MySQLi-Database-Class/pull/119 // https://github.com/joshcam/PHP-MySQLi-Database-Class/pull/119
if (version_compare (phpversion(), '5.4', '<')) if ($shouldStoreResult)
$stmt->store_result(); $stmt->store_result();
call_user_func_array(array($stmt, 'bind_result'), $parameters); call_user_func_array(array($stmt, 'bind_result'), $parameters);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment