0
所以,我之前就遇到過這個問題,並且從未解決過這個問題,但現在我又重新解決了這個問題,我真的希望解決它。sqlsrv_fetch_array在php中返回true
在PHP文件我執行下面幾行:
的問題是在querySelect(),你可以看到下面下來..
$stmt = sqlsrv_query($dbconn, "SELECT * FROM USERS");
$row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC);
Logger::logg("ROW (not in method): " . var_export($row, true), LV);
querySelect("SELECT * FROM USERS",$dbconn);
而且我得到以下幾點: (本第一個輸出是正確的,並選擇第一個用戶,正如你所看到的返回一個關聯數組)。然後在querySelect $行中每次都是真實的。 (有更多的這一點,因爲它會爲每個用戶ofcourse輸出...)
07/25/12 12:11:26 - ROW (not in method): array (
'LopNr' => 1,
'Mail' => 'xxxx ',
'Password' => 'xxx',
'Auth' => '1',
'DisplayName' => 'xxx ',
'sdsd' => xx,
'sdsd' => 'xxx',
'ts' => 1342093599,
'Cell' => NULL,
'WantsSMS' => xxx,
).
07/25/12 12:11:27 - Query: SELECT * FROM USERS.
07/25/12 12:11:27 - ROW: true.
07/25/12 12:11:27 - ROW: true.
07/25/12 12:11:27 - ROW: true.
07/25/12 12:11:27 - ROW: true.
07/25/12 12:11:27 - ROW: true.
07/25/12 12:11:27 - ROW: true.
07/25/12 12:11:27 - ROW: true.
07/25/12 12:11:27 - ROW: true.
07/25/12 12:11:27 - ROW: true.
07/25/12 12:11:27 - ROW: true.
07/25/12 12:11:27 - ROW: true.
07/25/12 12:11:27 - ROW: true.
07/25/12 12:11:27 - ROW: true.
07/25/12 12:11:27 - ROW: true.
07/25/12 12:11:27 - ROW: true.
07/25/12 12:11:27 - ROW: true.
07/25/12 12:11:27 - ROW: true.
07/25/12 12:11:27 - ROW: true.
07/25/12 12:11:27 - ROW: true.
07/25/12 12:11:27 - ROW: true.
querySelect實現這樣的:
function querySelect($query, $dbconn, $fetchLimit = 1000000)
{
$stmt = sqlsrv_query($dbconn, $query);
Logger::logg(LOGG_QRY_ERR_VERBOSE . $query, LV);
if (!$stmt)
{
Logger::logg(LOGG_QRY_ERR);
throw new Exception(ERR_QUERY);
}
$resultArray = array();
while ($row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC) && $fetchLimit > 0)
{
Logger::logg("ROW: " . var_export($row, true), LV);
$resultArray[] = $row;
$fetchLimit--;
}
return $resultArray;
}
哦,現在你指出來,它是如此明顯,謝謝! – netigger 2012-07-25 10:59:17
沒問題;去過也做過。樂意效勞。 – Hobo 2012-07-25 12:41:22