所以在我使用 sqlsrv 函数之前,我使用的是 MySQL 函数。
该代码对我来说非常完美,但现在我已经用 sqlsrv 替换了 MySQL 函数,它给了我这个错误。
sqlsrv_fetch_array() expects parameter 2 to be long
用于计数的代码是这样的:
$conn = sqlsrv_connect( $serverName, $connectionInfo);
$tsql = "SELECT * FROM login WHERE username = '".($_SESSION['username'])."'";
$res = sqlsrv_query($conn, $tsql);
while($row = sqlsrv_fetch_array($res, SQLSRV_FETCH_ASSOC)) {
$aantalATV = $row['ATV'];
$aanvragenATV = "SELECT COUNT(soort) AS totaal FROM goedgekeurd WHERE username = '".($_SESSION['username'])."' AND soort='ATV' ";
$rowATV = sqlsrv_fetch_array($conn, $aanvragenATV);
$aantalATV= $aantalATV - $rowATV[0];
echo "aantal ATV dagen resterende:" .$aantalATV."<br />";
}
问题出在哪里,是需要更改的查询吗?
任何帮助表示赞赏!
基于以下答案的新代码片段:Rikesh
$aantalATV = $row['ATV'];
$aanvragenATV = "SELECT COUNT(soort) AS totaal FROM goedgekeurd WHERE username = '".($_SESSION['username'])."' AND soort='ATV' ";
$res = sqlsrv_query($conn, $aanvragenATV);
$rowATV = sqlsrv_fetch_array($res, SQLSRV_FETCH_NUMERIC);
$aantalATV= $aantalATV - $rowATV[0];
echo "aantal ATV dagen resterende:" .$aantalATV."<br />";