ora_error

(PHP 3, PHP 4, PHP 5 <= 5.1.0RC1)

ora_error -- Gets an Oracle error message

Description

string ora_error ( [resource cursor_or_connection] )

Returns an error message of the form XXX-NNNNN where XXX is where the error comes from and NNNNN identifies the error message.

Замечание: Support for connection ids was added in 3.0.4.

On Unix versions of Oracle, you can find details about an error message like this: $ oerr ora 00001 00001, 00000, "unique constraint (%s.%s) violated" // *Cause: An update or insert statement attempted to insert a duplicate key // For Trusted ORACLE configured in DBMS MAC mode, you may see // this message if a duplicate entry exists at a different level. // *Action: Either remove the unique restriction or do not insert the key



ora_error
rob at towner dot cx
17-May-2004 04:56
You can use ora_error() to output the reason for a failed ora_logon() connection attempt. To do this, call ora_error() without any parameters. This works for php versions >= 4.0.2.

<?php
$conn
= @ora_logon("user@wrongTNS", "pass");

if (!
$conn) {
   echo
"Unable to connect to the database.<BR>\n";
   echo
ora_error(), "\n";
}
?>

This will output:

Unable to connect to the database.<BR>
ORA-12154: TNS:could not resolve service name
mihailsbo at lycos dot ru
17-Jun-2003 02:52
When your program is performing an Ora_Fetch, and your session is terminated by a database administrator, your fetch will fail, but the ora_error( your_connection ) will return 0. You can check the ora_error( your_cursor ), it will return 28 (ORA-00028: your session has been killed).
weiliang at yahoo dot com
09-Oct-2002 02:25
# Check this one out. PHP 4.2.2 with Oracle nad OCI8
<?php

    
class panera_oracle
    
{
      
      
/* Private Variables      ******************************************* */
      
      
var $db_conn;
       var
$db_cursor;
       var
$db_record_set;
 
      
/* Open an Oracle connect ****************************************** */

      
function connect($orauser, $tns, $password)
       {
          
$conn_str=$orauser . '@' . $tns;

          
$conn = ora_logon($conn_str,$password);
           if (!
$conn )
           {
              
$this->post_ora_error($conn);
              
$this->db_conn = "NULL";
           }
           else
           { 
$this->db_conn = $conn; }

           return;
       }

      
/* Disconnect from Oracle ****************************************** */

      
function disconnect()
       {
          
ora_logoff($this->db_conn);
           return;
       }

      
/* Post ORA - Error ***** ****************************************** */

      
function post_ora_error($ora_handle)
       {
           if (
ora_errorcode($ora_handle) )
           {
               echo
"Oracle Error - ".ora_error($ora_handle)."<br>\n";
               return -
1;
           }
           return
1;
       }

      
/* Execute query and return cursor handle ************************* */
      
      
function execute_query($query)
       {
          
$this->db_cursor=ora_open($this->db_conn);
           if (
$this->post_ora_error($this->db_cursor) > 0 )
           {
              
ora_parse($this->db_cursor,$query,0);
               if (
$this->post_ora_error($this->db_cursor) > 0 )
               {
                
ora_exec($this->db_cursor);
                 if (
$this->post_ora_error($this->db_cursor) > 0 )
                 {
                     return
1;
                 }
                 else { return -
1; }
               }
               else { return -
1; }
           }
           else { return -
1; }
          
       }
   }

?>

<?php

     $oracle
= new panera_oracle;
    
$query="SELECT * from AUDIT_LOAD_TYPES order by load_type_id";

    
$oracle->connect("pan_ods","shekel_proddw","panods");
  
     if (
$oracle->execute_query($query) > 0 )
     {
      
$oracle->db_record_set = array();

       while (
ora_fetch_into($oracle->db_cursor, $oracle->db_record_set, ORA_FETCHINTO_NULLS | ORA_FETCHINTO_ASSOC) )
       {
               echo
$oracle->db_record_set['LOAD_TYPE_ID']  . " ";
               echo
$oracle->db_record_set['LOAD_TYPE_DESC'] . " ";
               echo
$oracle->db_record_set['PACKAGE_NAME']  . " ";
               echo
$oracle->db_record_set['PROCEDURE_NAME'] . " ";

              
$rows=ora_numrows($oracle->db_cursor);

               echo
$rows;
               echo
"<BR>";
         }
     }

    
ora_close($oracle->db_cursor);
    
$oracle->disconnect();

?>

<ora_doora_errorcode>
 Last updated: Tue, 15 Nov 2005