문을 취소합니다. 즉, 문에 대해 보류 중인 결과를 삭제합니다. 이 함수가 호출된 후 sqlsrv_prepare를 사용하여 문이 준비되면 문을 다시 실행할 수 있습니다. 해당 문과 연관된 모든 결과가 사용된 경우 이 함수를 호출할 필요가 없습니다.
구문
sqlsrv_cancel( resource $stmt)
매개 변수
$stmt: 취소할 문입니다.
반환 값
부울 값: 작업이 성공한 경우 true가 반환되고 그렇지 않은 경우 false가 반환됩니다.
예
다음 예제에서는 AdventureWorks 데이터베이스를 대상으로 하여 쿼리를 실행한 다음 $salesTotal 변수가 지정된 양에 도달할 때까지 결과를 사용하고 개수를 셉니다. 나머지 쿼리 결과는 삭제됩니다. SQL Server와 AdventureWorks 데이터베이스가 로컬 컴퓨터에 설치되어 있다고 가정합니다. 명령줄에서 이 예제를 실행하면 모든 출력이 콘솔에 기록됩니다.
<?php
/* Connect to the local server using Windows Authentication and
specify the AdventureWorks database as the database in use. */
$serverName = "(local)";
$connectionInfo = array( "Database"=>"AdventureWorks");
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if( $conn === false )
{
echo "Could not connect.\n";
die( print_r( sqlsrv_errors(), true));
}
/* Prepare and execute the query. */
$tsql = "SELECT OrderQty, UnitPrice FROM Sales.SalesOrderDetail";
$stmt = sqlsrv_prepare( $conn, $tsql);
if( $stmt === false )
{
echo "Error in statement preparation.\n";
die( print_r( sqlsrv_errors(), true));
}
if( sqlsrv_execute( $stmt ) === false)
{
echo "Error in statement execution.\n";
die( print_r( sqlsrv_errors(), true));
}
/* Initialize tracking variables. */
$salesTotal = 0;
$count = 0;
/* Count and display the number of sales that produce revenue
of $100,000. */
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.\n";
/* Cancel the pending results. The statement can be reused. */
sqlsrv_cancel( $stmt);
?>
참고
sqlsrv_prepare 및 sqlsrv_execute 조합을 사용하여 준비되고 실행된 문은 sqlsrv_cancel을 호출한 후에 sqlsrv_execute를 사용하여 다시 실행할 수 있습니다. sqlsrv_query를 사용하여 실행된 문은 sqlsrv_cancel을 호출한 후에 다시 실행할 수 없습니다.