Deprecated: The each() function is deprecated. This message will be suppressed on further calls in /home/zhenxiangba/zhenxiangba.com/public_html/phproxy-improved-master/index.php on line 456
PHP: Ora_Do - Manual
[go: Go Back, main page]

PHP  
downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
search for in the  
<Ora_CommitOnOra_Error" width="11" height="7"/>
view the version of this page
Last updated: Thu, 07 Apr 2005

Ora_Do

(PHP 3, PHP 4 , PHP 5)

Ora_Do -- パース、実行、取得

説明

int ora_do ( int conn, string query)

この関数は、簡単のためora_parse()ora_exec()ora_fetch() を組み合わせたものです。この関数は、クエリをパース、実行し、結果 の最初のレコードを取得します。

成功時にTRUE、エラー時にFALSEを返します。エラーに関する詳細は、 ora_error()および ora_errorcode()関数を用いて取得することが可能 です。

ora_parse(),ora_exec(), ora_fetch()も参照下さい。



add a note add a note User Contributed Notes
Ora_Do
bakerst at ctt dot com
15-Oct-2002 03:55
As far as I'm concerned, this ora_do function should not be used in most cases. I was unable to catch errors when using this function, b/c it does the first fetch for you before you can even check if there's anything to fetch. Therefore, if there's a chance you won't get records back when running your query, using this function will not make it any easier for you. The best way to retrieve your data is to use this process:

$strThis = ora_logon("username@sid", "password");
$my_cursor = ora_open($my_db_conn);
ora_parse($my_cursor, $my_query, 0);
ora_exec($my_cursor);

then, so you don't get the "NO DATA FOUND" error from oracle when trying to fetch 0 records, check if it is possible to fetch the first record:

if (ora_fetch($my_cursor)) {
   do soemthing;
} else {
   raise an error (query returned no records);
}

don't forget, when you do the check, if the result is true, then you just fetched the first record. so if you try to do another fetch afterwards, that will not be the first record, it will be the second record. so use this method if it works for you.

easy, huh?
russell at REMOVE_CAPS_TO_MAIL dot loosenut dot com
28-Mar-2002 01:13
Remember that this function includes an implicit ora_fetch (so the first row is on the cursor, if it exists).  I think this problem has probably gotten "everyone" at one time or another... at least once... :-)

A fairly generic retrieval segment that, given an SQL query in $query (and with the proper Oracle credentials), will perform a database query on your database and return the results in a single variable:

   // Null out results array
   $results = array();

   putenv( "ORACLE_HOME=/path/to/oracle/productdir/version" );

   $ora_conn = ora_logon( "${oracle_user}@${oracle_db}",
                           $oracle_pw );

   // Parse, exec and fetch...
   $ora_cur = ora_do( $ora_conn, $query );

   if ( $ora_cur ){
     $numCols = ora_numcols( $ora_cur );  // Figure out how many columns

     // Get the first fetched row and put it in to our array...
     $row = array();
     for( $i = 0; $i < $numCols; $i++ ){  // Loop through columns
       array_push( $row, ora_getcolumn( $ora_cur, $i ) );
     }
     array_push( $results, $row );

     // Fetch rows, one at a time, putting them in their own
     // array.  Each row should be appended to the array of
     // results..
     while ( ora_fetch( $ora_cur ) ){      // Get each row
       $row = array();
       for( $i = 0; $i < $numCols; $i++ ){  // Loop through columns
         array_push( $row, ora_getcolumn( $ora_cur, $i ) );
       }
       array_push( $results, $row );
     }
   }

   ora_logoff( $ora_conn );

   // Result set is now in an array of rows, each containing an
   // array of columns
   if ( count( $results ) ){
     print_r( $results );
   } else {
     print( "No rows returned.\n" );
   }

Note: for a null result set, ora_do() may also drop a warning depending on how you have error reporting configured in the script or your PHP.INI file.  You might want to include:

   // Turn off error reporting to the user - let me handle
   // it myself...
   error_reporting( 0 );

And make sure you properly handle all errors yourself (such as failues on ora_conn() as well as ora_do()).
owend at obscure dot org
02-Mar-2001 02:32
I couldn't figure out how this worked until I looked at the PHP source code. The documentation does not mention that what ora_do returns is in fact a cursor, not just an integer true/false flag.  So the following snippet illustrates how I have been using it:

$cur = ora_do($conn, $query);
$foo = ora_getcolumn($cur,0);
... etc ...

<Ora_CommitOnOra_Error" width="11" height="7"/>
 Last updated: Thu, 07 Apr 2005
show source | credits | sitemap | contact | advertising | mirror sites 
Copyright © 2001-2005 The PHP Group
All rights reserved.
This mirror generously provided by: HappySize, Inc.
Last updated: Wed Feb 23 18:30:07 2005 JST