5 Replies Latest reply: Apr 3, 2012 12:24 PM by Gogala Mladen RSS

    Replacement of mysql_num_rows

    RENGANATHANMG
      Hi All,


      what are all the different ways to achieve the replacement of mysql_num_rows() ?


      Thanks
        • 1. Re: Replacement of mysql_num_rows
          Gogala Mladen
          Surprisingly, it's oci_num_rows(). That's a real surprise when you have in mind that both databases, Oracle RDBMS and MySQ,L are produced by the same company and that there is a conscious effort to keep the programming interfaces consistent.
          If you're using ADOdb (a smart choice), you must set $ADODB_COUNTRECS to true and then use $rs->RecordCount().
          • 2. Re: Replacement of mysql_num_rows
            cj
            I'm surprised! oci_num_rows was introduced in PHP 5.0. mysql_numrows() is in PHP 3, maybe even earlier. Both of these were released well before 2009.
            • 3. Re: Replacement of mysql_num_rows
              RENGANATHANMG
              Hi,

              As far as I know, no. oci_num_rows only returns affected rows on update/insert/delete statements.

              how to know how many records you are going to fetch ?*(without using count() )*
              • 4. Re: Replacement of mysql_num_rows
                Gogala Mladen
                Can you please do me a favor and test your assumptions? Here is a very simple test:

                #!/usr/bin/php
                <?php
                if (!$db=oci_connect('scott','tiger','apex41')) {
                die("Cannot connect to the database");
                }
                $qry='select * from emp';
                $csr=oci_parse($db,$qry);
                if (!oci_execute($csr)) {
                die("Something is screwed up with the SQL");
                } else {
                while ($row=oci_fetch_array($csr,OCI_NUM)) {
                printf("EMPNO=%d\n",$row[0]);
                }
                printf("The number of returned rows is:%d\n",oci_num_rows($csr));
                }
                ?>

                The result is expected:
                mgogala@mladen ~]$ /tmp/num_test.php
                EMPNO=7369
                EMPNO=7499
                EMPNO=7521
                EMPNO=7566
                EMPNO=7654
                EMPNO=7698
                EMPNO=7782
                EMPNO=7788
                EMPNO=7839
                EMPNO=7844
                EMPNO=7876
                EMPNO=7900
                EMPNO=7902
                EMPNO=7934
                The number of returned rows is:14

                Now, why do you expect someone else to write your test cases? What you did is rude. Your assumptions are wrong but you don't invest any effort at all and expect someone else to do that. This is a board owned by Oracle and I am not an administrator here, but this is ridiculous. How long would it take you to write such a test case? If the answer is "more than 5 minutes", you should give up programming and look for a new and promising career in chopping wood.
                • 5. Re: Replacement of mysql_num_rows
                  Gogala Mladen
                  BTW, you cannot know how many records you're going to fetch. Nobody can, it's your decision. PHP in the version 5.4 is still not capable of mind reading. You can only know how many records have you fetched. Oracle is not Pythia, an early leader in the decision support system. There is no knowing in advance how many records will the cursor return, without using "select count(*)". If you are looking for pagination, consider having "next" and "prev" links, without the page number.
                  BTW, Pythia also used SQL, which was interpreted as "Said Quixotically on Laurel".