php - PHP 中的多个结果集?

标签 php resultset

在 .NET SqlDataReader 中可以检索多个记录集:

    Dim Connection As New SqlConnection(SomeConnectionString)
    'Note that the command will generate three result
    Dim Command As New SqlCommand("select '1a', '1b'; " & _
        "select '2a', '2b', '2c'; " & _
        "select '3a', '3b'; ", Connection)
    Dim Reader As SqlDataReader

    Connection.Open()

    Reader = Command.ExecuteReader

    Do
        While Reader.Read
            'Do something with the data
        End While
    Loop While (Reader.NextResult) 'Proceed to next result

    Reader.Close()
    Connection.Close()

.NextResult 将读者移动到下一个结果。如何在 PHP 中执行此操作?我基本上想避免多次往返数据库。

注意:.Read 移动到下一行,而 .NextResult 移动到下一个结果。

1 个查询,3 个结果:

结果 1

1a 1b

结果 2

2a 2b 2c

结果 3

3a 3b

注意:行不等于结果。结果更像是一个表格或一组行。

最佳答案

如果你正在使用 PDO,你可以通过使用 PDOStatement->nextRowset() 来做到这一点.这是否受支持完全取决于您连接到的数据库以及您使用的 PDO 驱动程序。

关于php - PHP 中的多个结果集?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7117094/

相关文章:

php - 如何使用 PHP 从 HTML 中提取特定内容?

php - 为 MySql 行提供几个唯一的 ID,并使用 php 显示具有一个特殊 ID 的所有行

java - JDBC 结果集行为异常

php - 无法连接数据库MySql

php - 为什么变量应该有 public 或 private 或 protect 但函数不应该在类中

java - JDBC 结果集光标位置

java - RuntimeException - 耗尽结果集 - 怎么会发生?

java - 从 getCursorName 函数读取数据时出现异常 "positioned update not supported"

php - 正则表达式验证用户名

java - 如果ResultSet取值并存储在内存中,为什么关闭后无法使用ResultSet对象?