sqlsrv_execute
(사용 가능한 버전 정보가 없으며 Git에만 있을 수 있음)
sqlsrv_execute — sqlsrv_prepare()로 준비된 명령문을 실행합니다.
sqlsrv_execute(resource $stmt
): bool
sqlsrv_prepare()로 준비된 명령문을 실행합니다. 이 함수는 다른 매개변수 값으로 준비된 명령문을 여러 번 실행하는 데 이상적입니다.
매개변수
stmt
- sqlsrv_prepare()에서 반환된 명령문 리소스입니다.
반환 값
성공하면 true
를, 실패하면 false
를 반환합니다.
Examples
예제 #1 sqlsrv_execute() 예제
이 예에서는 sqlsrv_prepare()를 사용하여 명령문을 준비하고 sqlsrv_execute()를 사용하여 여러 번(다른 매개변수 값으로) 재실행하는 방법을 보여줍니다.
<?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 = "UPDATE Table_1
SET OrderQty = ?
WHERE SalesOrderID = ?";
// Initialize parameters and prepare the statement.
// Variables $qty and $id are bound to the statement, $stmt.
$qty = 0; $id = 0;
$stmt = sqlsrv_prepare( $conn, $sql, array( &$qty, &$id));
if( !$stmt ) {
die( print_r( sqlsrv_errors(), true));
}
// Set up the SalesOrderDetailID and OrderQty information.
// This array maps the order ID to order quantity in key=>value pairs.
$orders = array( 1=>10, 2=>20, 3=>30);
// Execute the statement for each order.
foreach( $orders as $id => $qty) {
// Because $id and $qty are bound to $stmt1, their updated
// values are used with each execution of the statement.
if( sqlsrv_execute( $stmt ) === false ) {
die( print_r( sqlsrv_errors(), true));
}
}
?>
메모
변수를 매개변수로 사용하는 명령문을 준비하면 변수가 명령문에 바인딩됩니다. 즉, 변수 값을 업데이트하면 다음에 명령문을 실행할 때 업데이트된 매개변수 값으로 실행됩니다. 한 번만 실행하려는 명령문의 경우 sqlsrv_query()를 사용하십시오.
기타
- sqlsrv_prepare() - 쿼리 실행 준비
- sqlsrv_query() - 쿼리 준비 및 실행