connect to sugarcrm and get some data in my custom php file

I made in new custom php file lets say e.g sample.php placed in root folder accessing it through a ajax call in any module but i am not able to connect to database or perform any operation. How to do that anyone can help?

  • Hi Umar,

    Ideal way to go by sugar entry point checking but you can use following code as well.

    Can you please write following code in top of the "sample.php" file and try to make your ajax call and database operations same as sugar way?

    <?php

    if(!defined('sugarEntry'))

      define('sugarEntry', true);

    require_once ('include/entryPoint.php');

    global $db, $current_user;

    << YOUR CODE HERE >>

    // HERE $db and $current_user are accessible same as sugar any module file

    << END HERE>>

    ?>

  • Hello Devang,

    Thankyou for your reply.
    Buddy i am trying to just echo the logged in username by doing this 

    $name = $current_user->name;

    echo $name;
    But nothing happening. Any idea whats wrong?

    Thank-You
    M.Umar Akhlaq

  • Can you please share your exact same file with me if possible?

  • My ajax call

    $("#btn_ajax").click(function(){

            $.ajax({

           type : "POST",

           url : "sample_info.php",

           datatype : "html",

           success : function Display(msg) {

            $("#ajax_div").html(msg);

           }

          });

             });

    and sample.php

    <?php

    if(!defined('sugarEntry'))

      define('sugarEntry', true);

    require_once ('include/entryPoint.php');

    global $db, $current_user;

    $name = $current_user->name;

    echo $name;

    ?>

    thats it just trying to echo the name.

  •  

    Umar, You are calling sample_info.php and  any made code in sample.php

    Can you please check it by call with sample.php?

  • Sorry its a typing mistake here buddy its sample_info.php

  • Ok, I think you have placed this file within your <MODULE NAME FOLDER>.

    Can you please locate your file to <ROOT> location of CRM and try making this ajax call?

    No need to change in code. Only move your file to <ROOT> location.

    For eg : where config.php file is there.

  • My sample_info.php file is already placed in root folder where config and config_override files are placed.

  • Please try this one.

    <?php

    if(!defined('sugarEntry'))

      define('sugarEntry', true);

    require_once ('include/entryPoint.php');

    global $db;

    print_r($db);

    ?>

  • MysqliManager Object and few other things in array

1 2