why doesn't work the 'include(config.php)'?

Hello everybody

I am sending data by ajax from a custom module to make inquiries with the data sent, so I include a connectionDB.php with this data:


$pdo= new PDO($sevidor, $usuario, $password, array(PDO::MYSQL_ATTR_INIT_COMMAND=>"SET NAMES utf8"));
//echo "connect..";
}catch(PDOException $e){
echo "Bad connection..".$e->getMessage();

But at the time of executing the ajax in the php log it shows me this:

PHP Warning:  include(modules/key_Surveys/metadata/connectionDB.php): failed to open stream: No such file or directory 

And this:

PHP Warning:  include(): Failed opening 'modules/key_Surveys/metadata/connectionDB.php' for inclusion (include_path='.:/usr/share/php:/usr/share/pear')

I hope you could help me, thank you very much.


  • Although the PHP warning appears to be unrelated to the sugar_config, you can use: 

    global $sugar_config;

    instead of the include.

    As for your error the problem is in the script where you include the connectionDB.php.

    All includes should have a full path relative to the sugar root so you should give the path relative to that.

    The error suggests that your script is in modules/key_Surveys/metadata/ and that you included the connectionDB.php just by using a statement like:

    include_once ('connectionDB.php') without the path.


    You are probably going to use the connectionDB.php from multiple scripts at some point.

    I suggest you put your connectionDB.php in your utilities folder: 


    The functions in the scripts included in that directory will be included for you and can be used in any script.

    See: https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_9.2/Architecture/Extensions/Utils/ 



  • for using $sugar_config variables, other option is just replace $sugar_config with $GLOBALS['sugar_config'].

    However looking at the error, you may need to move your connectionDB.php to root folder if looking to make a direct Call ( however not recommended).