PHP 中的多个结果集?
在 .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
注意:行不等于结果。结果更像是一个表或一组行。
In .NET SqlDataReader can retrieve multiple record set:
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()
The .NextResult
moves the reader to the next result. How to do this in PHP? I basically want to avoid many round trips to the database.
Note: .Read
here moves the next row while .NextResult
moves to the next result.
1 query, 3 results:
result 1
1a 1b
result 2
2a 2b 2c
result 3
3a 3b
Note: Row is not equal to result. Result is much more like a table or set of rows.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您使用 PDO,则可以通过使用 PDOStatement->nextRowset() 来执行此操作。是否支持完全取决于您要连接的数据库以及您使用的 PDO 驱动程序。
You can do this if you are using PDO, by using PDOStatement->nextRowset(). Whether this is supported or not depends entirely on the database you are connecting to, and which PDO driver you use.