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
ora_error
説明
string ora_error ( [resource cursor_or_connection] )XXX-NNNNN という形式のエラーメッセージが返されます。ここで、 XXXは何処からエラーが発生したか、 NNNNNはエラーメッセージを識別します。
注意: 接続IDのサポートは、3.0.4 で追加されました。
UNIX版の Oracle 上では、 以下のようにエラーメッセージに関する詳細を得ること ができます。 $ 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
18-May-2004 08:56
18-May-2004 08:56
mihailsbo at lycos dot ru
17-Jun-2003 06:52
17-Jun-2003 06: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
10-Oct-2002 06:25
10-Oct-2002 06: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();
?>