sqlsrv_send_stream_data

PHP ドライバーのダウンロード

パラメーター ストリームからデータをサーバーに送信します。 最大 8 キロバイト (8K) のデータが、sqlsrv_send_stream_data の呼び出しごとに送信されます。

注意

既定では、クエリを実行すると、すべてのストリーム データがサーバーに送信されます。 この既定の動作を変更しない場合は、ストリーム データをサーバーに送信するために 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. */
$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)

ドキュメントのコード例について