sqlsrv_send_stream_data

下載 PHP 驅動程式

將參數資料流中的資料傳送至伺服器。 每次呼叫 sqlsrv_send_stream_data 時最多可傳送 8 K 的資料。

注意

根據預設,在查詢執行時,所有的資料流資料都會傳送至伺服器。 如果未變更此預設行為,您即無需使用 sqlsrv_send_stream_data 將資料流資料傳送至伺服器。 如需變更預設行為的相關資訊,請參閱 sqlsrv_querysqlsrv_prepare的「參數」一節。

語法

  
sqlsrv_send_stream_data( resource $stmt)  

參數

$stmt:對應至執行之陳述式的陳述式資源。

傳回值

布林值:如果還有資料要傳送,則為 true 。 否則為 false

範例

下列範例會以資料流的形式開啟產品評論,並將其傳送至伺服器。 在執行時傳送所有資料流資料的預設行為會停用。 此範例假設本機電腦上已安裝 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));  
}  
  
/* Define the query. */  
$tsql = "UPDATE Production.ProductReview   
         SET Comments = (?)   
         WHERE ProductReviewID = 3";  
  
/* Open parameter data as a stream and put it in the $params array. */
$data = 'Insert any lengthy comment here.';
$comment = fopen('data:text/plain,'.urlencode($data), 'r');
$params = array(&$comment);
  
/* Prepare the statement. Use the $options array to turn off the  
default behavior, which is to send all stream data at the time of query  
execution. */  
$options = array("SendStreamParamsAtExec"=>0);  
$stmt = sqlsrv_prepare($conn, $tsql, $params, $options);
  
/* Execute the statement. */  
sqlsrv_execute( $stmt);  
  
/* Send up to 8K of parameter data to the server with each call to  
sqlsrv_send_stream_data. Count the calls. */  
$i = 1;  
while (sqlsrv_send_stream_data($stmt)) {
      echo "$i call(s) made.\n";  
      $i++;  
}  
  
/* Free statement and connection resources. */  
sqlsrv_free_stmt( $stmt);  
sqlsrv_close( $conn);  
?>  

另請參閱

SQLSRV 驅動程式 API 參考

更新資料 (Microsoft Drivers for PHP for SQL Server)

關於文件中的程式碼範例