在.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
注意:行不等于结果。结果更像是一个表或一组行。