PHP PDO Buffered query problem

前端 未结 3 1088
小鲜肉
小鲜肉 2020-12-10 07:10

I\'m having some serious problems with the PHP Data Object functions. I\'m trying to loop through a sizeable result set (~60k rows, ~1gig) using a buffered query to avoid fe

相关标签:
3条回答
  • 2020-12-10 07:48

    Or maybe you could try mysql functions instead:

    while ($row = mysql_fetch_row($query)) {
    ...
    }
    

    Which will definitely be faster, since that foreach statement makes an impression to use fetchAll() instead fetch() each row

    0 讨论(0)
  • 2020-12-10 07:50

    If I understand this right, buffered queries involve telling PHP that you want to wait for the entire result set before you begin processing. Prior to PDO, this was the default and you had to call mysql_unbuffered_query if you wanted to deal with results immediately.

    Why this isn't explained on the PDO MySQL driver page, I don't know.

    0 讨论(0)
  • 2020-12-10 07:55

    You could try to split it up into chunks that aren't big enough to cause problems:

    <?php    
    $id = 0;
    $rQuery = $Database->query('SELECT id FROM mytable ORDER BY id ASC LIMIT 100');
    
    do {
        stuff($rQuery);
        $id += 100;
    } while ( $rQuery = $Database->query(
                'SELECT id FROM mytable ORDER BY id ASC LIMIT 100 OFFSET '.$id
              )
            );
    ?>
    

    ...you get the idea, anyway.

    0 讨论(0)
提交回复
热议问题