使用php获取sql server表中的行数


Getting number of rows in a sql server table using php

我正在尝试使用PHP获得表中的行数(或主键数),然后将结果输出到网页。我是SQL server的新手,这不会给我任何结果

//code above omitted and connected to the database
$query_count = "SELECT COUNT(*) FROM ElectronicShop";
$data_count = sqlsrv_query($connectString, $query_count) or die(print_r(sqlsrv_errors(SQLSRV_ERR_ALL), true));
//$row_count = sqlsrv_fetch_row($data_count);
echo "<br>ROW COUNT:".sqlsrv_fetch_object($data_count)."<br>";

可能

//code above omitted and connected to the database
$query_count = "SELECT COUNT(*) AS myCounter FROM ElectronicShop";
$data_count = sqlsrv_query($connectString, $query_count) or die(print_r(sqlsrv_errors(SQLSRV_ERR_ALL), true));
//$row_count = sqlsrv_fetch_row($data_count);
$row = sqlsrv_fetch_object($data_count);
echo "<br>ROW COUNT:".$row->myCounter."<br>";

从文档:https://php.net/sqlsrv-fetch-object