PHP.nl

sqlsrv_cancel

sqlsrv_cancel

Cancels a statement

bool **sqlsrv_cancel** resource $stmt

Cancels a statement. Any results associated with the statement that have not been consumed are deleted. After has been called, the specified statement can be re-executed if it was created with . Calling is not necessary if all the results associated with the statement have been consumed. sqlsrv_cancel``sqlsrv_prepare``sqlsrv_cancel

stmtThe statement resource to be cancelled.

return.success

Voorbeeld: example

<?php
$serverName = "serverName\sqlexpress";
$connectionInfo = array( "Database"=>"dbName", "UID"=>"username", "PWD"=>"password");
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if( $conn === false ) {
     die( print_r( sqlsrv_errors(), true));
}

$sql = "SELECT Sales FROM Table_1";

$stmt = sqlsrv_prepare( $conn, $sql);

if( $stmt === false ) {
     die( print_r( sqlsrv_errors(), true));
}

if( sqlsrv_execute( $stmt ) === false) {
     die( print_r( sqlsrv_errors(), true));
}

$salesTotal = 0;
$count = 0;

while( ($row = sqlsrv_fetch_array( $stmt)) && $salesTotal <=100000)
{
     $qty = $row[0];
     $price = $row[1];
     $salesTotal += ( $price * $qty);
     $count++;
}

echo "$count sales accounted for the first $$salesTotal in revenue.<br />";

// Cancel the pending results. The statement can be reused.
sqlsrv_cancel( $stmt);
?>

The main difference between and is that a statement resource cancelled with can be re-executed if it was created with . A statement resource cancelled with cannot be re-executed. sqlsrv_cancel``sqlsrv_free_stmt``sqlsrv_cancel``sqlsrv_prepare``sqlsrv_free_statement

sqlsrv_free_stmt``sqlsrv_prepare