我正在尝试计算表中的行数,但是我收到以下错误:
sqlsrv_num_rows()期望参数1为资源,给定数组
这是我的SQL:
<?php
$getPriceRequests = "SELECT * FROM PriceRequests";
$resultPricerequests = sqlsrv_query($conn, $getPriceRequests);
$priceRequests = sqlsrv_fetch_array($resultPricerequests, SQLSRV_FETCH_ASSOC);
$numPriceRequests = sqlsrv_num_rows($priceRequests);
?>
但由于某种原因,当我打印出以下内容时,我得到了上述错误:
<?php echo $numPriceRequests; ?>
答案 0 :(得分:0)
如果要计算表中的行数,请在数据库中执行,而不是在应用程序中执行。
正确的查询是:
public static void DistinctValues<T>(List<T> list)
{
list.Sort();
int src = 0;
int dst = 0;
while (src < list.Count)
{
var val = list[src];
list[dst] = val;
++dst;
while (++src < list.Count && list[src].Equals(val)) ;
}
if (dst < list.Count)
{
list.RemoveRange(dst, list.Count - dst);
}
}
然后将值读回应用程序。
答案 1 :(得分:0)
将代码更改为以下内容以获得所需结果:
<?php
$getPriceRequests = "SELECT * FROM PriceRequests";
$params = array();
$options = array( "Scrollable" => SQLSRV_CURSOR_KEYSET );
$resultPriceRequests = sqlsrv_query($sapconn2, $getPriceRequests, $params, $options);
$numPriceRequests = sqlsrv_num_rows($resultPriceRequests);
?>