php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #68498 oci_error returns false after ORA-00001
Submitted: 2014-11-25 17:15 UTC Modified: 2014-11-26 13:57 UTC
From: joe at thook dot me Assigned: sixd (profile)
Status: Closed Package: OCI8 related
PHP Version: 5.5.19 OS: CentOS
Private report: No CVE-ID: None
 [2014-11-25 17:15 UTC] joe at thook dot me
Description:
------------
Behavior seems similar to this (resolved) issue: https://bugs.php.net/bug.php?id=42134

Project using ZF1 fails to handle ORA-00001 (Unique constraint violation) warning as an error.

1. SQL statement is sent to Oracle DB adapter using OCI driver (2.0.8)
2. oci_execute() of INSERT statement would cause unique constraint violation, statement fails correctly. 
3. PHP Warning is issued (verified with FirePHP and in Apache logs). PHP error_reporting is E_ALL on this development server.
4. ZF1 attempts to generate Exception thus:
   throw new Zend_Db_Statement_Oracle_Exception(oci_error($this->_stmt));
5. oci_error returns false. Exception is not generated correctly because error array is not produced.

Expected result:
----------------
When oci_execute() throws ORA-00001 and issues a PHP Warning, oci_error should produce the error array in accordance with PHP's error_reporting setting.


Actual result:
--------------
oci_error() returns false despite Warning issued.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-11-26 02:38 UTC] sixd@php.net
-Status: Open +Status: Feedback -Assigned To: +Assigned To: sixd
 [2014-11-26 02:38 UTC] sixd@php.net
Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves. 

A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external 
resources such as databases, etc. If the script requires a 
database to demonstrate the issue, please make sure it creates 
all necessary tables, stored procedures etc.

Please avoid embedding huge scripts into the report.

Please give the SQL to create the table and a non-ZFW testcase.  Thanks.
 [2014-11-26 02:56 UTC] sixd@php.net
Looks OK in my testcase.

<?php

/*
create table cjt (c1 number unique);
insert into cj1 values (1);
commit;
*/

error_reporting(E_ALL);
ini_set('display_errors', 'Off');

$c = oci_connect('hr', 'welcome', 'localhost/orcl');

if (!$c) {
    $m = oci_error();
    trigger_error('oci_connect error: Could not connect to database: '. $m['message'], E_USER_ERROR);
}

$s = oci_parse($c, "insert into cjt values (1)");
if (!$s) {
    $m = oci_error($c);
    trigger_error('oci_parse error: Could not parse statement: '. $m['message'], E_USER_ERROR);
}

$r = oci_execute($s);
if (!$r) {
    $m = oci_error($s);
    trigger_error('oci_execute error: Could not execute statement: '. $m['message'], E_USER_ERROR);
}

?>

Gives:

$ php56 uc.php
PHP Warning:  oci_execute(): ORA-00001: unique constraint (HR.SYS_C0010813) violated in uc.php on line 25
PHP Fatal error:  oci_execute error: Could not execute statement: ORA-00001: unique constraint (HR.SYS_C0010813) violated in uc.php on line 28
 [2014-11-26 13:57 UTC] joe at thook dot me
-Status: Feedback +Status: Closed
 [2014-11-26 13:57 UTC] joe at thook dot me
Closing this issue.

Thanks to the boiled-down test script above, we were able to run the test in a couple scenarios. We discovered it's apparently an issue in Zend Server's ZRay debug tool. With ZRay on, the oci_error info was disappearing. As soon as ZRay was turned off, the error info started appearing in the exception as expected.
 
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Wed Aug 17 03:05:44 2022 UTC