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:

include('config.php');
$db_host_name=$sugar_config[dbconfig][db_host_name];
$db_user_name=$sugar_config[dbconfig][db_user_name];
$db_password=$sugar_config[dbconfig][db_password];
$db_name=$sugar_config[dbconfig][db_name];

////////////////////////////////////////////
$sevidor="mysql:dbname=".$db_name.";host=".$db_host_name;
$usuario=$db_user_name;
$password=$db_password;
try{
$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.

Regards.

Parents
  • 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: 

    <sugar_root>/custom/Extension/application/Ext/Utils/

    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/ 

     

    FrancescaS

Reply
  • 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: 

    <sugar_root>/custom/Extension/application/Ext/Utils/

    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/ 

     

    FrancescaS

Children
No Data