I need to include DB.php (pear library) to one of my files. I already tried to include and require that file but it reports the following error:

Warning: main(DB.php) [function.main]: failed to create stream: No such file or directory in /home/webpage/public_html/folderx/index.php on line 2

Warning: main() [function.main]: Failed opening 'DB.php' for inclusion (include_path='') in /home/webpage/public_html/folderx/index.php on line 2

I allready checked the phpinfo() and it has the include_path ".:/usr/local/lib/php"
I dont know why it is not working! does anyone knows what could be happening?? because in the error message it says (include_path='') so maybe the include path is not working!!
I really need to solve this problem today so I would really apreaciate any help. Thanks!

    I talkes to one of the server administrators and he says that he thinks that the library is installed in:

    /usr/lib/php

    and not in:

    .:/usr/local/lib/php

    I can change the include path but can I specify manually the path in the file?
    something like:

    include(/usr/lib/php/DB.php)
    or
    include(.:/usr/lib/php/DB.php)

    is this correct?

      I would think that including with an absolute instead of a relative directory should fix the problem.

        Right; and get rid of the dots in your code. They are fine in php.ini, but will not work in coding an absolute pathname. They tell unix to look in the current dir '.' and ':' the next dir listed, '/usr/local/lib/php.'

        include '/usr/lib/php/DB.php';

        should do the trick, if that's really where this file is located. Mine is in /usr/local/lib/php (FreeBSD, Apache+mod_php...)

          Its very weird what its happening:

          I used - require "/usr/local/lib/php/DB.php" and it worked! so I know for sure that the pear library IS installed in /usr/local/lib/php. the strange thing is that the include path in the php.ini is set to ".:/usr/local/lib/php" and it does not work! so if I use this code:

          require "DB.php" -> does not work

          require "/usr/local/lib/php/DB.php" -> reports the following error:

          Warning: main(PEAR.php) [function.main]: failed to create stream: No such file or directory in /usr/local/lib/php/DB.php on line 25

          Fatal error: main() [function.main]: Failed opening required 'PEAR.php' (include_path='') in /usr/local/lib/php/DB.php on line 25

          I think this happens because the file DB.php includes the file PEAR.php but it cant locate it because the include path is not working! but I dont know why it is not working because the path is correct.
          I am operating in redhat linux. I know that PEAR.php IS in the path because if I type the code: require "/usr/local/lib/php/PEAR.php" it does not report an error.

          I was thinking in modifying DB.php and modify the include or require PEAR.php code by specifing the path manually but i dont have access to that file. should I try to take out the " .: " in the include path? ehat else could I do to solve my problem!

            Well, I'll take a stab at it, but I'm an idiot 🙂

            $maybe=require "/usr/local/lib/php/DB.php";
            
            if (!$maybe) {
               require "/usr/local/lib/php/PEAR.php";
               }

            But I doubt that it helps....

            how 'bout permissions on PEAR.php??

              Hi,

              there are a lot of posts regarding this issue (seems to be some kind of bug). Most people were able to get around that problem with one or both of the two solutions:

              1)

              put the following directive on top of your php script:

              ini_set('include_path', ini_get('include_path'));

              2)

              put a .htaccess file in your document_root which contains:

              php_value include_path .:/usr/local/lib/php

              Thomas

                Umm why isnt the DB.php inside one of the folders of the site? And why are you using the long path?

                WHy isnt it something like
                include("../includes/DB.php");

                ?😕

                  Thank you tsinka!!! you saved my life!!
                  all the problem was solved by adding:

                  ini_set('include_path', ini_get('include_path'));

                  thanks again

                    5 years later

                    Dear Tsinka,

                    I think I'm having the same problem, PHP Pear is installed and when I view the phpinfo() this is the path:

                    include_path .;C:\php5\pear .;C:\php5\pear

                    I included as you suggested to another user this on the top of the script:

                    ini_set('include_path', ini_get('include_path'));

                    but still, when launch the php script, I receive the following message:

                    Warning: include(Mail.php) [function.include]: failed to open stream: No such file or directory in E:\Apache Software Foundation\Apache2.2\htdocs\contacts.php on line 7

                    Warning: include() [function.include]: Failed opening 'Mail.php' for inclusion (include_path='.;C:\php5\pear') in E:\Apache Software Foundation\Apache2.2\htdocs\contacts.php on line 7

                    Fatal error: Class 'Mail' not found in E:\Apache Software Foundation\Apache2.2\htdocs\contacts.php on line 114

                    if please comes something in your mind how to try to fix.
                    Thank you in advance.

                      Write a Reply...