Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8163747
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T19:07:57+00:00 2026-06-06T19:07:57+00:00

I wrote the following snippet in order to handle errors. (Page.php gets included in

  • 0

I wrote the following snippet in order to handle errors.

(Page.php gets included in index page through : array( falseNamePage=> page.php, ….ect))

Perfoming some tests to see how it reacts, I delete a page.php from public_html.

RESULT :

-error logging ok

-alert email sending ok

-recording in DB : ERROR :

Notice: Undefined variable: $database in /home/…/public_html/index.php on line 40

Warning: mysql_query() expects parameter 2 to be resource, null given in /home/…/public_html/index.php on line 40 “impossible to connect with DB2”

I do not understands why it fails connecting to the DB in this case and sends back an error.

DB Connection works fine in every other cases ( delete, select,update, insert …)

function errorHandler($errno, $errstr, $errfile, $errline)
    {
    require_once('connection.php');
    $now = time();
    $date = date("Y-m-d H:i:s",$now);    
    switch ($errno) {
        case E_NOTICE:
        case E_USER_NOTICE:
        case E_DEPRECATED:
        case E_USER_DEPRECATED:
        case E_STRICT:

            ............ 5 first cases code...............

        case E_WARNING:
        case E_USER_WARNING:            

            $message_warning = "Warning : ".$errno." : ".$errstr." : ".$errfile." : ".$errline;
            error_log ( $message_warning ,0);
            $mail = 'my_mail@yahoo.com';  $sujet = $message_warning;  $body_warning = $date." : ".$message_warning;                             
            mail($mail,'=?UTF-8?B?'.base64_encode($sujet).'?=',stripslashes($body_warning));
            $query_warning  =" INSERT INTO errorlog (severity,errno,errstr,errfile,errline,time) 
            VALUES ('WARNING','".$errno."','".$errstr."','".$errfile."','".$errline."','".$date."')";           
            $result_warning = mysql_query($query_warning,$database) or die("impossible to connect with DB2");
                break;

        case E_ERROR:
        case E_USER_ERROR:

       ............... 2 last cases code ..........
    }       
}    
set_error_handler("errorHandler");  

The final question is :

WHY IS AN INCLUDE ERROR ECHOED 4 TIMES ?

Does the system attempts 4 times to “open stream”?

I did :

function errorHandler($errno, $errstr, $errfile, $errline)
           {
        if     ($errno == E_NOTICE )
        { echo "<br/>".$errno."== E_NOTICE<br/>";}
        if     ($errno == E_USER_NOTICE)
        { echo "<br/>".$errno."== E_USER_NOTICE<br/>";}
        if     ($errno == E_DEPRECATED)
        { echo "<br/>".$errno."== E_DEPRECATED<br/>";}
        if     ($errno == E_USER_DEPRECATED)
        { echo "<br/>".$errno."== E_USER_DEPRECATED<br/>";}
        if     ($errno == E_STRICT)
        { echo "<br/>".$errno."== E_STRICT<br/>";}
        if     ($errno == E_WARNING)
        { echo "<br/>".$errno."== E_WARNING<br/>";}
        if     ($errno == E_USER_WARNING)
        { echo "<br/>".$errno."== E_USER_WARNING<br/>";}
        if     ($errno == E_ERROR)
        { echo "<br/>".$errno."== E_ERROR<br/>";}
        if     ($errno == E_USER_ERROR)
        { echo "<br/>".$errno."== E_USER_ERROR<br/>";}
           }             
           set_error_handler("errorHandler");   

RESULT :

2== E_WARNING

2== E_WARNING

2== E_WARNING

2== E_WARNING

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T19:07:58+00:00Added an answer on June 6, 2026 at 7:07 pm

    Your problem is simple, and, in my opinion, it’s YAPHPB: you’re using require_once within a function definition, hoping that the file will be included just once – to shape up a function’s body.

    But it doesn’t work like that: this code will be parsed each time (well, it’s a bit simplified, but the reasons still the same) the function will get called. And because it’s require_once, your file will be included just once indeed – only when the function is called first time. All the next calls will skip the file’s inclusion, hence $database will not be defined.

    The easiest way to fix it is to replace require_once with require. But I think the problem just will be covered – but not solved. The real solution would be to restructure your code in such way that your $database will actually become a record in registry – and will be lazily extracted from that registry if needed.

    There are many ways to implement such behaviour: we often use Zend_Registry component for that. And in this topic there are some examples of how to use this component effectively.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When I wrote the following snippet for experimenting purposes, it raised the hover-error (see
I wrote the following code snippet in VS2010: #pragma once #include stdafx.h #ifndef SECURITY_WIN32
The following snippet is from a little app I wrote using the Qt framework.
I am using g++ to compile some code. I wrote the following snippet: bool
i wrote the following snippet according to The iPhone Developer's Cookbook C5 - Tables
I wrote the following snippet to get rid of excessive spaces in slabs of
In the following snippet, you can see my two collatz functions I wrote in
I wrote the following code snippet: void foo() { struct _bar_ { int a;
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
For learning purposes, I wrote the following code snippet: for(int i=0;i<10;i++) { for(int j

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.