HektoR Posted January 7, 2009 Share Posted January 7, 2009 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 More sharing options...
GingerRobot Posted January 7, 2009 Share Posted January 7, 2009 How big is the text file in question? Link to comment https://forums.phpfreaks.com/topic/139873-fatal-error/#findComment-731787 Share on other sites More sharing options...
HektoR Posted January 7, 2009 Author Share Posted January 7, 2009 34.6 mb Link to comment https://forums.phpfreaks.com/topic/139873-fatal-error/#findComment-731790 Share on other sites More sharing options...
MadnessRed Posted January 7, 2009 Share Posted January 7, 2009 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 More sharing options...
rhodesa Posted January 7, 2009 Share Posted January 7, 2009 what about using fopen and reading the file line by line? Link to comment https://forums.phpfreaks.com/topic/139873-fatal-error/#findComment-731803 Share on other sites More sharing options...
HektoR Posted January 7, 2009 Author Share Posted January 7, 2009 second is easier but my site is on web hosting . and i cant change it. Link to comment https://forums.phpfreaks.com/topic/139873-fatal-error/#findComment-731805 Share on other sites More sharing options...
HektoR Posted January 7, 2009 Author Share Posted January 7, 2009 rhodesa what you say? you want to change that code with fopen function ? i baza.txt i have mysql queries like "insert into xxx(xxx,qqqq,rrr,tttt) values (xxx,xxxx,xxx,xxx)"; Link to comment https://forums.phpfreaks.com/topic/139873-fatal-error/#findComment-731816 Share on other sites More sharing options...
HektoR Posted January 7, 2009 Author Share Posted January 7, 2009 any ideas? Link to comment https://forums.phpfreaks.com/topic/139873-fatal-error/#findComment-731826 Share on other sites More sharing options...
rhodesa Posted January 7, 2009 Share Posted January 7, 2009 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 More sharing options...
HektoR Posted January 7, 2009 Author Share Posted January 7, 2009 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 More sharing options...
rhodesa Posted January 7, 2009 Share Posted January 7, 2009 Is that a valid query? Link to comment https://forums.phpfreaks.com/topic/139873-fatal-error/#findComment-731855 Share on other sites More sharing options...
MadnessRed Posted January 15, 2009 Share Posted January 15, 2009 Is that a valid query? doesn't look right to me Link to comment https://forums.phpfreaks.com/topic/139873-fatal-error/#findComment-737991 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.