sqlsrv_send_stream_data
将参数流中的数据发送到服务器。每次调用 sqlsrv_send_stream_data 时都会发送多达 8K 的数据。
备注
默认情况下,执行查询时所有流数据都将发送至服务器。如果此默认行为不变,则您不必使用 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)