sqlsrv_next_result

(No version information available, might only be in Git)

sqlsrv_next_resultMakes the next result of the specified statement active

Description

sqlsrv_next_result(resource $stmt): mixed

Makes the next result of the specified statement active. Results include result sets, row counts, and output parameters.

Parameters

stmt

The statement on which the next result is being called.

Return Values

Returns true if the next result was successfully retrieved, false if an error occurred, and null if there are no more results to retrieve.

Examples

Example #1 sqlsrv_next_result() example

The following example executes a batch query that inserts into a table and then selects from the table. This produces two results on the statement: one for the rows affected by the INSERT and one for the rows returned by the SELECT. To get to the rows returned by the SELECT, sqlsrv_next_result() must be called to move past the first result.

<?php
$serverName 
"serverName\sqlexpress";
$connectionInfo = array("Database"=>"dbName""UID"=>"userName""PWD"=>"password");
$conn sqlsrv_connect$serverName$connectionInfo);

$query "INSERT INTO Table_1 (id, data) VALUES (?,?); SELECT * FROM TABLE_1;";
$params = array(1"some data");
$stmt sqlsrv_query($conn$query$params);

// Consume the first result (rows affected by INSERT) without calling sqlsrv_next_result.
echo "Rows affected: ".sqlsrv_rows_affected($stmt)."<br />";

// Move to the next result and display results.
$next_result sqlsrv_next_result($stmt);
if( 
$next_result ) {
   while( 
$row sqlsrv_fetch_array$stmtSQLSRV_FETCH_ASSOC)){
      echo 
$row['id'].": ".$row['data']."<br />"
   }
} elseif( 
is_null($next_result)) {
     echo 
"No more results.<br />";
} else {
     die(
print_r(sqlsrv_errors(), true));
}
?>

See Also

Here you can write a comment


Please enter at least 10 characters.
Loading... Please wait.
* Pflichtangabe
There are no comments available yet.

PHP cURL Tutorial: Using cURL to Make HTTP Requests

cURL is a powerful PHP extension that allows you to communicate with different servers using various protocols, including HTTP, HTTPS, FTP, and more. ...

TheMax

Autor : TheMax
Category: PHP-Tutorials

Midjourney Tutorial - Instructions for beginners

There is an informative video about Midjourney, the tool for creating digital images using artificial intelligence, entitled "Midjourney tutorial in German - instructions for beginners" ...

Mike94

Autor : Mike94
Category: KI Tutorials

Basics of views in MySQL

Views in a MySQL database offer the option of creating a virtual table based on the result of an SQL query. This virtual table can be queried like a normal table without changing the underlying data. ...

admin

Autor : admin
Category: mySQL-Tutorials

Publish a tutorial

Share your knowledge with other developers worldwide

Share your knowledge with other developers worldwide

You are a professional in your field and want to share your knowledge, then sign up now and share it with our PHP community

learn more

Publish a tutorial