我正在使用php的sqlsrv扩展名,并且从简单查询中获取行时遇到问题。 我的查询是一个选择,它应该返回133228行但是当我试图显示行时我只得到15。 我已经找到了答案,但无法找到解决方案,这是我第一次使用此扩展程序。我已经找到了关于同一问题的上一个问题的答案,但在这种情况下问题是双重调用sqlsrv_fetch_array,我肯定不会这样做。
这是我的问题:
$text = "<p>701082 Range Control Board from Dacor is a manufacturer approved part. The part has been repaired to Dacor's specifications resulting in the highest performance with superior quality</p>";
preg_replace('/The part has been repaired to.*?<\/p>/U', '</p>', $text);
print_r($text);
正如我所说,上面的查询返回15时应该是133228行。
我错过了什么? 提前谢谢。
答案 0 :(得分:0)
$data = [];
$result_num = false;
// get rows num if have any
$result_count_res = sqlsrv_query(
$conn,
$query,
[],
[ "Scrollable" => SQLSRV_CURSOR_KEYSET ]
);
if( $result_count_res === false) {
echo "Row count false";
}else{
// set row num
$result_num = sqlsrv_num_rows( $result_count_res );
}
if($result_num){
// run another query to retrive results
$result_res = sqlsrv_query(
$conn,
$query,
[],
[ "Scrollable" => SQLSRV_CURSOR_FORWARD ]
);
if( $result_res === false) {
// get errors from query
die( print_r( sqlsrv_errors(), true) );
}else{
// run through "for" loop to retrive all results
for($i = 0; $i < $result_num; $i++){
$data[] = sqlsrv_fetch_array( $result_res, SQLSRV_FETCH_ASSOC);
}
}
sqlsrv_free_stmt( $result_res );
}else{
echo "Row count false";
}
echo '<pre>';
var_dump($data);
echo '</pre>';