sqlsrv_send_stream_data
將參數資料流中的資料傳送至伺服器。每一個 sqlsrv_send_stream_data 呼叫最多會傳送 8 KB 的資料。
注意
根據預設,所有資料流資料都會在執行查詢時傳送給伺服器。如果預設行為並未變更,您就不必使用 sqlsrv_send_stream_data 傳送資料流資料給伺服器。如需有關變更預設行為的資訊,請參閱<sqlsrv_query>或<sqlsrv_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. */
$comment = fopen( "data://text/plain,[ Insert lengthy comment.]", "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);
?>
另請參閱
概念
其他資源
API 參考 (SQL Server Driver for PHP)
更新資料 (SQL Server Driver for PHP)