2011-08-19 69 views
3

在.NET中SqlDataReader的可檢索多個記錄集:PHP中有多個結果集?

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 

注:行不等於導致。結果更像是一個表或一組行。

回答

3

如果您使用的是PDO,則可以使用PDOStatement->nextRowset()。這是否得到支持完全取決於您要連接的數據庫以及您使用的PDO驅動程序。

+0

我認爲就是這樣。 MySQL或MSSQL?你怎麼看? – dpp

+0

我不認爲MySQL(或者至少PDO mysql驅動程序)支持多個結果集。 PostgreSQL可能會,而且我也沒有任何關於PDO的SQL Server驅動程序的第一手經驗,所以我不能對此發表評論。 – cdhowie

+0

Noooooooo !!我只會對此做一些研究。 Thanks1 – dpp