PHP
downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

ora_error> <ora_commiton
Last updated: Sun, 25 Nov 2007

view this page in

ora_do

(PHP 4, PHP 5 <= 5.0.5)

ora_do — Parse, Exec, Fetch

설명

resource ora_do ( resource $connection , string $query )

Parse and execute a statement, then fetch the first result row.

This function is a quick combination of ora_parse(), ora_exec() and ora_fetch().

매개변수

connection

A connection identifier, opened with ora_logon().

query

The SQL statement.

반환값

This function returns a cursor index or FALSE on failure. Details about the error can be retrieved using the ora_error() and ora_errorcode() functions.

변경 기록

버전 설명
5.1.0

oracle 확장은 권장되지 않습니다. oci8를 사용하십시오.

주의

There is no direct replacement for ora_do() in oci8. Instead, use a sequence of oci_parse(), oci_excute(), and one of the oci_fetch_*() functions.



ora_error> <ora_commiton
Last updated: Sun, 25 Nov 2007
 
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_error> <ora_commiton
Last updated: Sun, 25 Nov 2007
 
 
show source | credits | stats | sitemap | contact | advertising | mirror sites