#1
  1. A Change of Season
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2004
    Posts
    2,566
    Rep Power
    171

    How come the script does not print anything after query execution?


    Hello; I am working on a query that selects +3 million records from the database. It works fine as it shows number of affected rows, but there is an issue!

    When the LIMIT in query is less than 1000 (approximately), it prints everything echoed after DB::Load()->Execute. But when the limit gets bigger (for example 4000 records), it still runs and shows the number of affected rows but does not print anything after DB::Load()->Execute!

    In other words script runs successfully but does not print anything after query execution!

    Script 1
    PHP Code:
    $query "SELECT id FROM something LIMIT 5";
    echo 
    "Before execution";
    $packages DB::Load()->Execute($query$arg)->returnArray();
    echo 
    "After execution";
    // prints Before executionAfter execution 
    Script 2
    PHP Code:
    $query "SELECT id FROM something LIMIT 30000";
    echo 
    "Before execution";
    $packages DB::Load()->Execute($query$arg)->returnArray();
    echo 
    "After execution";
    // prints Before execution 
    What is a girl to do in this crazy world?
    Thank you
  2. #2
  3. Come play with me!
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    13,742
    Rep Power
    9397
    I bet you're hitting the memory limit. Have you set error_reporting and display_errors appropriately, either in code (since this is a runtime problem) or in your php.ini?
  4. #3
  5. A Change of Season
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2004
    Posts
    2,566
    Rep Power
    171
    Originally Posted by requinix
    I bet you're hitting the memory limit. Have you set error_reporting and display_errors appropriately, either in code (since this is a runtime problem) or in your php.ini?
    Hello. I got
    Allowed memory size of 33554432 bytes exhausted (tried to allocate 43148176 bytes) in php
    I thought I try ini_set('memory_limit', '-1');
    Would this be a good idea? Cause it works.
  6. #4
  7. Come play with me!
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    13,742
    Rep Power
    9397
    It's not. You gave your script carte blanche to do whatever it wanted with memory. Like try to use all of it.

    If appropriate, paginate your queries: do some number at a time. Chunked, if you will.
    If not then go for an unbuffered query. That means the results will not be automatically buffered into memory and you can go through them one at a time, but (1) you don't see that functionality in a lot of database frameworks and (2) it has some drawbacks, such as not allowing you to do a second query on that connection until you retrieve all the rows in the result.

IMN logo majestic logo threadwatch logo seochat tools logo