3 Replies Latest reply: Jan 11, 2012 11:53 AM by cj RSS

    Problem with trigger_error

    Iwawa
      Hi to All

      I have create this test file:
      <?php
          $dbHost = "sles11sp1.lan";
          $dbHostPort="1521";
          $dbServiceName = "sles11";
          $usr = "test";
          $pswd = "mypwd";
          $dbConnStr = "(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=".$dbHost.")(PORT=".$dbHostPort."))
           (CONNECT_DATA=(SERVICE_NAME=".$dbServiceName.")))";
          if(!$dbConn = oci_connect($usr,$pswd,$dbConnStr)) {
             $err = oci_error();
             trigger_error('Could not establish a connection: ' . $err['message'], E_USER_ERROR);
          };
          $strSQL = "SELECT TO_CHAR(SYSDATE, 'HH:MI:SS') ctime FROM DUAL";
          $stmt = oci_parse($dbConn,$strSQL);
          if (!oci_execute($stmt)) {
             $err = oci_error($stmt);
             trigger_error('Failed to execute the query: ' . $err['message'], E_USER_ERROR);
          };
          oci_fetch($stmt); 
          $rslt = oci_result($stmt, 'CTIME');
          print "<h3>The current time is ".$rslt."<h3>";
      ?>
      When I run the file in the Browser all work fine. But if i modify for example the password in order to verify the connection error, the error is not displayed and the page is empty.

      Can You help me to find wich error is in my php file ?

      Kind Greetings
      Gaetano
        • 1. Re: Problem with trigger_error
          cj
          Do you need to add "| E_USER_ERROR" to the php.ini setting of error_reporting?
          • 2. Re: Problem with trigger_error
            Iwawa
            I want display in the browser a message with error verified during the execution.

            Thanks
            Gaetano
            • 3. Re: Problem with trigger_error
              cj
              Check your php.ini settings for display_errors and error_reporting. See http://us.php.net/manual/en/errorfunc.configuration.php#ini.error-reporting
              You can find your php.ini location and settings with the phpinfo() function.

              Almost all production PHP applications shouldn't expose internal errors to end users because this is a security leak. Instead, scripts should "catch" errors, log them to a web server-side file, and generate a pretty error page to show the user. See the Error Handling chapter of the updated PHP & XE guide: http://docs.oracle.com/cd/E17781_01/appdev.112/e18555/ch_seven_error.htm#sthref243