Re: Executing SQL query with ODBC
| From: | Simon Rees | Date: | Tue, 09 Nov 2004 11:12:05 +0000 |
| Subject: | Re: Executing SQL query with ODBC | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-37204@lists.php.net to get a copy of this message | ||
Hi
Most databases don't return the number of rows in the results of a select
statement to odbc_num_rows. See:
http://www.php.net/manual/en/function.odbc-num-rows.php
Usually the way to determine the number of rows a select returns is to
either fetch them all and count them or do an additional aggregate query.
It depends on your requirements.
I presume that this behaviour is because in most cases the database engine
does not make the number of rows in a result set available to the driver.
The only way the php interface could calculate the number of rows would be
to fetch them all which may be inefficient - say if you were only
interested in the first row out of a possible 100. [anybody else care to
comment?]
Note, after an insert, update and delete statements odbc_num_rows does
return the number of rows affected.
cheers Simon
On Tuesday 09 November 2004 08:09, Petrus Ali Saputra wrote:
> Here is my code:
> $conn = odbc_connect("Ta Fara","","");
> $query = "SELECT * FROM Config";
> $result = odbc_exec($conn, $query);
> echo odbc_num_rows($result);
>
> This code never give me a 0 result even there is some data. How can I
> solve it? Thank you.
> --
> Petrus Ali Saputra
> ==========================================================
> Addr. : Karang Empat Besar 76
> Surabaya 60133
> East Java, Indonesia
> Phone : 62-31-381-7866
> 62-31-6010-2653
> 62-81-23000-254
> ----------------------------------------------------------
> A professional web hosting for your business and corporate
> URL : http://attractive.as/hostmania
> ----------------------------------------------------------
> Mau kredit mobil baru/bekas dengan bunga rendah?
> URL : http://fantastic.as/kreditmobil
--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Simon Rees | srees@nildram.co.uk |
ORA-03113: end-of-file on communication channel
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~