PHP PDO multiple select query consistently dropping last rowset

前端 未结 2 952
臣服心动
臣服心动 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:31

    To avoid that PDOException just use columnCount:

    while ($statment->columnCount()) {
         $rowset = $statment->fetchAll(PDO::FETCH_ASSOC);
         $statment->nextRowset();
    }
    
    0 讨论(0)
  • 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.

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