• <bdo id='xFPBA'></bdo><ul id='xFPBA'></ul>

    <small id='xFPBA'></small><noframes id='xFPBA'>

      <legend id='xFPBA'><style id='xFPBA'><dir id='xFPBA'><q id='xFPBA'></q></dir></style></legend>
      <tfoot id='xFPBA'></tfoot>
    1. <i id='xFPBA'><tr id='xFPBA'><dt id='xFPBA'><q id='xFPBA'><span id='xFPBA'><b id='xFPBA'><form id='xFPBA'><ins id='xFPBA'></ins><ul id='xFPBA'></ul><sub id='xFPBA'></sub></form><legend id='xFPBA'></legend><bdo id='xFPBA'><pre id='xFPBA'><center id='xFPBA'></center></pre></bdo></b><th id='xFPBA'></th></span></q></dt></tr></i><div id='xFPBA'><tfoot id='xFPBA'></tfoot><dl id='xFPBA'><fieldset id='xFPBA'></fieldset></dl></div>
    2. 如何使用 ODBC 连接在 PHP 中获取结果集中的计数或行数?

      How to Get The Count or The Number Of Rows In A Result Set In PHP using ODBC Connection?(如何使用 ODBC 连接在 PHP 中获取结果集中的计数或行数?)
      <legend id='AN1NE'><style id='AN1NE'><dir id='AN1NE'><q id='AN1NE'></q></dir></style></legend>

          <tfoot id='AN1NE'></tfoot>

            <small id='AN1NE'></small><noframes id='AN1NE'>

            <i id='AN1NE'><tr id='AN1NE'><dt id='AN1NE'><q id='AN1NE'><span id='AN1NE'><b id='AN1NE'><form id='AN1NE'><ins id='AN1NE'></ins><ul id='AN1NE'></ul><sub id='AN1NE'></sub></form><legend id='AN1NE'></legend><bdo id='AN1NE'><pre id='AN1NE'><center id='AN1NE'></center></pre></bdo></b><th id='AN1NE'></th></span></q></dt></tr></i><div id='AN1NE'><tfoot id='AN1NE'></tfoot><dl id='AN1NE'><fieldset id='AN1NE'></fieldset></dl></div>
              • <bdo id='AN1NE'></bdo><ul id='AN1NE'></ul>

                  <tbody id='AN1NE'></tbody>
                本文介绍了如何使用 ODBC 连接在 PHP 中获取结果集中的计数或行数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                当我在我的 PHP Web 应用程序中构建一个网页时,我的连接工作正常,但是当我想获取我在查询中使用的 SELECT 语句的行数时,它给了我 -1 !虽然我的结果集大约有 10 行.

                While I build a web page in My PHP web application, My Connection works ok but When I want to get the count of rows of the SELECT Statement I used in my query, It gives me -1 !! although my result set has about 10 rows.

                我想获得结果集的实际行数.我搜索了 PHP 手册 &文档,但我没有找到像 Count 函数之类的直接方法.

                I would like to get the actual number of result set rows. I searched the PHP Manual & documentation but I do not find a direct way like a Count function or something like that.

                我想知道我是否必须在另一个查询中创建一个 Count(*) SQL 语句并将其附加到我的连接以获取行数?

                I wonder if I have to make a Count(*) SQL Statement in another query and attach it to my Connection to get the Count of Rows ?

                有人知道一种简单直接的方法吗?

                Does any one knows an easy and direct way to get that ?

                odbc_num_rows 函数总是在结果中给出 -1,所以我无法获得实际的行数.

                the odbc_num_rows function always gives -1 in result so I can not get the actual number of rows.

                我的编程语言是 PHP,我的数据库引擎是 Sybase,连接数据库的方式是 ODBC.

                My Programming langauge is PHP and My Database Engine is Sybase and The Way to connect to Database is ODBC.

                这是我使用的代码:-

                <?PHP
                
                //PHP Code to connect to a certain database using ODBC and getting information from it
                
                //Determining The Database Connection Parameters
                $database = 'DatabaseName';
                $username = 'UserName';
                $password = 'Password';
                
                //Opening the Connection
                $conn = odbc_connect($database,$username,$password);
                
                //Checking The Connection
                if (!$conn)
                {
                exit("Connection Failed: " . $conn);
                }
                
                //Preparing The Query
                $sql = "SELECT * FROM Table1 WHERE Field1='$v_Field1'";
                
                //Executing The Query
                $rs = odbc_exec($conn,$sql);
                
                //Checking The Result Set
                if (!$rs)
                {
                exit("Error in SQL");
                }
                
                echo "<p align='Center'><h1>The Results</h1></p>";
                
                while ( odbc_fetch_row($rs) )
                
                {
                  $field1 = odbc_result($rs,1);
                  $field2 = odbc_result($rs,2);
                  $field3 = odbc_result($rs,3);
                  echo "field1 : " . $field1 ;
                  echo "field2 : " . $field2 ;
                  echo "field3 : " . $field3 ;
                }
                
                $RowNumber = odbc_num_rows($rs);
                
                echo "The Number of Selected Rows = " . $RowsNumber ; 
                
                //Closing The Connection
                odbc_close($conn);
                
                ?>
                

                感谢您的帮助:)

                推荐答案

                odbc_num_rows 似乎仅适用于 INSERT、UPDATE 和 DELETE 查询.

                odbc_num_rows seems to be reliable for INSERT, UPDATE, and DELETE queries only.

                手册说:

                使用 odbc_num_rows() 来确定 SELECT 后可用的行数将返回 -1 与许多驱动程序.

                Using odbc_num_rows() to determine the number of rows available after a SELECT will return -1 with many drivers.

                解决此行为的一种方法是在 SQL 中执行 COUNT(*).请参阅此处以获取示例.

                one way around this behaviour is to do a COUNT(*) in SQL instead. See here for an example.

                这篇关于如何使用 ODBC 连接在 PHP 中获取结果集中的计数或行数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
                PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
                mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
                Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
                Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
                Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)
                • <i id='Ve98Z'><tr id='Ve98Z'><dt id='Ve98Z'><q id='Ve98Z'><span id='Ve98Z'><b id='Ve98Z'><form id='Ve98Z'><ins id='Ve98Z'></ins><ul id='Ve98Z'></ul><sub id='Ve98Z'></sub></form><legend id='Ve98Z'></legend><bdo id='Ve98Z'><pre id='Ve98Z'><center id='Ve98Z'></center></pre></bdo></b><th id='Ve98Z'></th></span></q></dt></tr></i><div id='Ve98Z'><tfoot id='Ve98Z'></tfoot><dl id='Ve98Z'><fieldset id='Ve98Z'></fieldset></dl></div>

                  <small id='Ve98Z'></small><noframes id='Ve98Z'>

                • <tfoot id='Ve98Z'></tfoot>
                  • <bdo id='Ve98Z'></bdo><ul id='Ve98Z'></ul>

                            <tbody id='Ve98Z'></tbody>
                        • <legend id='Ve98Z'><style id='Ve98Z'><dir id='Ve98Z'><q id='Ve98Z'></q></dir></style></legend>