Showing posts from September, 2013

SugarCRM Database Query

Database query functions:
$bean->db or $GLOBALS[‘db’] or global $db are the objects of the databases.
// to execute the query
$result = $bean->db->query($query, true); OR $result = $GLOBALS['db']->query($query, true);
In this $query variable will have the query that you want to execute.

//To get the rowcounts:
$rowcount = $bean->db->getRowCount($result); OR $rowcount = $GLOBALS['db']->getRowCount($result);
This will return the number of rows affected or fetched in the variable $rowcount

//To fetch the data:

$resultData = $bean->db->fetchByAssoc($result); OR $resultData = $GLOBALS['db']->fetchByAssoc($result);

You can get the all data by the passing the $resultData variable in the while loop.

Insert the SugarCRM data in relational table

To set the relationship and set the data in table:
To set the data in the relationship table, use the below code.

//create the object of the table
$acc = new Account();

//key return by the saved data $relate_value = array('accounts_contacts_idb' => $contact_id);
//key value of related field $data_value = array('accounts_contacts_idb_ida' => $_REQUEST['account_id']);
//function call by the same object