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? Quote Link to comment 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? Quote Link to comment Share on other sites More sharing options...
HektoR Posted January 7, 2009 Author Share Posted January 7, 2009 34.6 mb Quote Link to comment 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. Quote Link to comment 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? Quote Link to comment 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. Quote Link to comment 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)"; Quote Link to comment Share on other sites More sharing options...
HektoR Posted January 7, 2009 Author Share Posted January 7, 2009 any ideas? Quote Link to comment 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"; ?> Quote Link to comment 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 : Quote Link to comment Share on other sites More sharing options...
rhodesa Posted January 7, 2009 Share Posted January 7, 2009 Is that a valid query? Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.