发布:2014/7/9 9:05:45作者:管理员 来源:本站 浏览次数:2459
返回上次执行的语句所修改的行数。此函数不返回 SELECT 语句返回的行数。
下面的示例显示 UPDATE 语句修改的行数。此示例假定本地计算机上已安装 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)); } /* Set up Transact-SQL query. */ $tsql = "UPDATE Sales.SalesOrderDetail SET SpecialOfferID = ? WHERE ProductID = ?"; /* Set parameter values. */ $params = array(2, 709); /* Execute the statement. */ $stmt = sqlsrv_query( $conn, $tsql, $params); /* Get the number of rows affected and display appropriate message.*/ $rows_affected = sqlsrv_rows_affected( $stmt); if( $rows_affected === false) { echo "Error in calling sqlsrv_rows_affected.\n"; die( print_r( sqlsrv_errors(), true)); } elseif( $rows_affected == -1) { echo "No information available.\n"; } else { echo $rows_affected." rows were updated.\n"; } /* Free statement and connection resources. */ sqlsrv_free_stmt( $stmt); sqlsrv_close( $conn); ?>
© Copyright 2014 - 2025 柏港建站平台 ejk5.com. 渝ICP备16000791号-4