Re: numRows() for oci8
| From: | Stig S. Bakken | Date: | Thu, 25 Jan 2001 09:52:07 +0000 |
| Subject: | Re: numRows() for oci8 | ||
| References: | 1 | Groups: | php.pear |
| Request: | Send a blank email to php-pear+get-1159@lists.php.net to get a copy of this message | ||
Thomas Fromm wrote:
>
> Hi,
>
> has anybody a good idea to get numrows of an oracle result?
>
> maybe something this: (could be implemented in the same way at the oci7 api)
>
> // {{{ numRows()
>
> /**
> * Get the number of rows in a result set.
> *
> * @param $query query of the select
> *
> * @access public
> *
> * @return int the number of rows in $result
> */
> function numRows($query=FALSE)
> {
> if(!$query){
> $query=$this->last_query;
> }
> $query=$this->modifyQuery($query);
> if(!preg_match('/^\s*SELECT/i', $query)){
> return 0;
> }
> $query="SELECT COUNT(*) FROM (".$query.")";
> if(!$stmt= @OCIParse($this->connection, $query)){
> return $this->raiseError();
> }
> if(!$success=@OCIExecute($stmt,OCI_DEFAULT)){
> return $this->raiseError();
> }
> if(!$data=@OCIFetchInto($stmt,$result,OCI_ASSOC+OCI_RETURN_NULLS){
> return $this->raiseError();
> }
> return $result["COUNT(*)"];
> }
>
> // }}}
> ( its untestet, just quick written in the mailclient... )
> maybe we can rewrite the original query and replace all selected fields with
> one count(*), that could be better ;-)
>
> any better ideas?
This is the same problem as with the ODBC backend. We have an
"optimize" option that is "performance" by default but can be set to
"portability". Hacks like this one could be enabled in "portability
mode". Sub-selects and stuff. Ewww. :-)
> another thing is, why not using @ in front of each databasefunction?
> if an error occurs, raiseError() schould do the rest.
Yup, there should be a @ in front of all native PHP function calls.
- Stig