Search code examples
phpmysqlmemoryfatal-error

Running out of memory with mysqli on php (256kB???)


I'm trying to execute an SELECT statement via PHP on a MySQL database. When I execute my script, I get an fatal error:

Fatal error: Allowed memory size of 262144 bytes exhausted (tried to allocate 94020 bytes)

Well, 256kB isn't enough for everybody, is it? How do I adjust this limit?

Regards

Chris

My code is:

ini_set('memory_limit', '1024MB');
  ...  
  // Create connection
  $mySQLConn = new mysqli($servername, $username, $password, $database);

  if ($mySQLConn->connect_error) {
    throw new Exception('Kann nicht auf DB verbinden: ' . $mySQLConn->connect_error);
  }
 
  
  $result = $mySQLConn->real_query("SELECT * FROM artikel;");
  $result = $mySQLConn->store_result(); // <- here I get this fatal error

Solution

  • https://www.php.net/manual/en/faq.using.php#faq.using.shorthandbytes says:

    What are all the available shorthand byte options?

    The available options are K (for Kilobytes), M (for Megabytes) and G (for Gigabytes; available since PHP 5.1.0), and are all case-insensitive. Anything else assumes bytes. 1M equals one Megabyte or 1048576 bytes.

    Don't use 1024MB. Use 1024M.