PDO multiple queries

后端 未结 1 685
暖寄归人
暖寄归人 2020-11-27 07:31

As of PHP version 5.3 PDO_MYSQL driver has been repleaced in favour of PDO_MYSQLND. It introduced support for multiple queries.

Though, I c

相关标签:
1条回答
  • 2020-11-27 07:48

    It turns out that you need to use PDOStatement::nextRowset.

    $stmt   = $db->query("SELECT 1; SELECT 2;");
    $stmt->nextRowset();
    var_dump( $stmt->fetchAll(PDO::FETCH_ASSOC) );
    

    This will return result for the second query.

    It is a bit odd implementation. It would certainly be easier if multi-query statement would just return both results sets under one array. However, the advantage is that this implementation allows to fetch every query using different FETCH styles.

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