MDB2 problem in PHP

Posted on 2009-04-25
Last Modified: 2013-12-12

I am using PEAR's MDB2 and I am faced with the following error.
Fatal error: Cannot redeclare class MDB2_Error in
/usr/share/php5/PEAR/MDB2.php on line 977

This happens in the login page if the query fails (if they user credentials are wrong). Probably happens in other places if wrong input is passed and the query fails.

It is not installation dependant, I have tested it in many setups. It is not PEAR dependant, I have created my own pear directory and changed the include path accordingly.

I need to make this error message dissapear and let the script die in a more legant way. Also, I would like to understand why it happens.

Thank you very much.
Question by:webspirit
    LVL 6

    Accepted Solution

    My guess would be that somewhere in your application there is a class definition for MDB2_Error.

    Search your whole application folder recursively for the text string MDB2_Error

    for Linux / OS X you can cd to the directory that your application resides in and:

    grep -R MDB2_Error ./

    For Windows I like to user notepad++ for my coding (or Zend Studio) and you can use the recursive find functions in there.

    If you find MDB2_Error being declared in any of your scripts you can probably comment out the section that declares it, or otherwise wrap the class definition in a check like this:

    if (!class_exists('MDB2_Error')) {
        // define MDB2_Error class here

    To stop the error messages showing you would have to disable error display:

    display_errors should be turned off for any production sites at any rate.

    To advise in more detail I'd have to see the actual script in question. Is it a standard / open source script?
    LVL 40

    Assisted Solution

    Your code probably includes a line something like ...

    include 'MDB2_Error';


    include 'MDB2_Error';

    This will probably already be included by PEAR. Remove the line. The exact value will depend upon the proper name of the file.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    As this topic comes over and over again in different forms, I've finally decided to write a short (yea, right...) article / tutorial about pagination with PHP with MySQL database. There are dozens of these kind of tutorials, I know - I wanted to mak…
    Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
    The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
    This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    26 Experts available now in Live!

    Get 1:1 Help Now