PHP PDO multiple select query consistently dropping last rowset

前端 未结 2 953
臣服心动
臣服心动 2021-01-05 13:46

I\'m experiencing what appears to be a bug using a PDO statement to make multiple selects.

I\'m building a SQL query that has many SELECTs, and regardless of how ma

2条回答
  •  無奈伤痛
    2021-01-05 14:32

    I think you are over complicating things with your do/while loop.

    Try a simple while loop instead:

    $pdo = /* connection stuff here */
    $sql = "select 1; select 2; select 3; select 4;";
    $statement = $pdo->query($sql);
    
    while($rowset = $statement->fetchAll()){
        //do stuff
    
        $statement->nextRowset();
    }
    

    This will continue looping while rowset does not have a false value which should then work exactly as you expect.

提交回复
热议问题