note 20262 deleted from function.ora-do by danbrown

From: Date: Fri, 26 Sep 2008 16:43:18 +0000
Subject: note 20262 deleted from function.ora-do by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-144807@lists.php.net to get a copy of this message
Note Submitter: russell at REMOVE_CAPS_TO_MAIL dot loosenut dot com ---- 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()).

« previous php.notes (#144807) next »