如何使用 Advantage PHP 扩展获取行数?

发布于 2024-12-10 15:22:16 字数 57 浏览 0 评论 0原文

如何使用 Advantage Database PHP 扩展从 SELECT 语句结果集中获取行数?

How can I get the number of rows from a SELECT statement result set using the Advantage Database PHP Extension?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

南城旧梦 2024-12-17 15:22:16

我最终编写了自己的函数,其工作方式与 mysql_num_rows 类似:

function my_num_rows($result) {
    ob_start(); // begin disable output from ads_result_all
    (int)$number = ads_result_all($result);
    ob_end_clean(); //close and clean the output buffer
    ads_fetch_row($r1, 0); // reset the result set pointer to the beginning
    if ($number >= 0){
         return $number;
    } else {
         return FALSE;
    }
}

它也可以重写以使用 ads_fetch_row 来计算行数,但这更容易满足我的需要。对于较大的结果集,使用 ads_result_all 可能会降低性能。

I ended up writing my own function that works similar to mysql_num_rows:

function my_num_rows($result) {
    ob_start(); // begin disable output from ads_result_all
    (int)$number = ads_result_all($result);
    ob_end_clean(); //close and clean the output buffer
    ads_fetch_row($r1, 0); // reset the result set pointer to the beginning
    if ($number >= 0){
         return $number;
    } else {
         return FALSE;
    }
}

It could also be rewritten to count the rows using ads_fetch_row but this was easier for what I needed. With large result sets there could be slower performance using ads_result_all.

呆° 2024-12-17 15:22:16

您必须在获取行时对行进行计数。 (您可以查看此知识库项目 070618-1888) 或者您可以使用 COUNT() 标量执行第二个查询(如果可能,建议排除 order by)

以下是边走边计数的示例:

$rStmt = ads_do ($rConn, "select id, name from table1");
$RowCount = 0;
while (ads_fetch_row($rStmt))
{
   $id = ads_result ($rStmt, "id");
   $name = ads_result($rStmt, "name");
   echo $id . "\t" . $name . "\n";
   $RowCount++;
}
echo "RowCount:" . $RowCount . "\n";

You will have to count the rows as they are fetched. (you can see this KB item 070618-1888) or you can execute a second query with the COUNT() scalar (suggest excluding order by if possible)

Here is an example of counting as you go:

$rStmt = ads_do ($rConn, "select id, name from table1");
$RowCount = 0;
while (ads_fetch_row($rStmt))
{
   $id = ads_result ($rStmt, "id");
   $name = ads_result($rStmt, "name");
   echo $id . "\t" . $name . "\n";
   $RowCount++;
}
echo "RowCount:" . $RowCount . "\n";
み零 2024-12-17 15:22:16

据我所知,在版本 12 中,您有 ads_num_rows() 函数。进一步使用请参阅官方文档。

In Version 12 as far as I know you have the function ads_num_rows(). Please see in official documentation for further usage.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文