Jump to content

Fatal error


HektoR

Recommended Posts

hi all.

i have error in script:

 

Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 36321232 bytes) in

 

my code is :

<?php 
$con = mysql_connect("","","");
if(!$con)
{
die('mysql error' . mysql_error());
}
mysql_select_db("",$con);

$queries = array_map('trim', file('baza.txt'));

foreach($queries as $query)
{
     // dumb way of stripping quotes off of beginning and quotes + semicolon off of the end.
     $query = substr($query,1,-2);
     mysql_query($query) or die('Query: ' . $query . '<br />Error: ' . mysql_error());
}
mysql_close($con);
?>

 

whats wrong?

Link to comment
https://forums.phpfreaks.com/topic/139873-fatal-error/
Share on other sites

34.6 mb

 

at a guess it is

36321232 bytes

 

you are trying to load a file into memory that is bigger than the memory allowance. as far as I can tell there are 3 possible solutions.

 

Decrease the size of the text file,

Increase the memory allowance for php (php.ini)

Create the script in c++ and run it via exec.

 

I would say that second is easier.

Link to comment
https://forums.phpfreaks.com/topic/139873-fatal-error/#findComment-731795
Share on other sites

try this:

 

<?php
set_time_limit(0);
mysql_connect("","","") or die('mysql error' . mysql_error());
mysql_select_db("") or die('mysql error' . mysql_error());

$file = 'baza.txt';
$fh = fopen($file,'r') or die("Failed to open file");
for($n=0;!feof($fh);$n++){
  $query = substr(trim(fgets($fh, 4096)),1,-2);
  mysql_query($query) or die('Query: ' . $query . '<br />Error: ' . mysql_error());
}
fclose($fh);
mysql_close();
print "Finished running $n queries";
?>

Link to comment
https://forums.phpfreaks.com/topic/139873-fatal-error/#findComment-731835
Share on other sites

Warning: set_time_limit() has been disabled for security reasons in

Query: INSERT INTO balance(id,pir_n,saxeli,gvari,misamarti,davalianeba,tarigi) VALUES ('2000148','','','xxx\ttt\','yyy;yyy;uuu','16.79','')

 

Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''yyy;yyy;uuu' at line 1

 

look at baza.txt :

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/139873-fatal-error/#findComment-731849
Share on other sites

  • 2 weeks later...

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.