Multiple result set in PHP?
In .NET SqlDataReader can retrieve multiple record set:
Dim Connection As New SqlConnection(SomeConnectionString)
'Note th开发者_开发知识库at 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.
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.
精彩评论