CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • Using CRM_Core_DAO class with Drupal 5.x and CiviCRM 1.9
Pages: [1]

Author Topic: Using CRM_Core_DAO class with Drupal 5.x and CiviCRM 1.9  (Read 3056 times)

posco

  • I post occasionally
  • **
  • Posts: 49
  • Karma: 8
Using CRM_Core_DAO class with Drupal 5.x and CiviCRM 1.9
February 02, 2008, 05:45:55 pm
I'm wondering what is required to use this class. For example, here is some code from my project:

Code: [Select]
$sql = 'SELECT id, name FROM civicrm_membership_status WHERE domain_id = %1;';
$params = array(1 => array(CIVICRM_DOMAIN_ID, 'Integer'));
$dao =& CRM_Core_DAO::executeQuery($sql, $params);

Can I just create a new DAO object this way without calling any of the other CiviCRM API functions? In other words, do I need to call civicrm_initialize(true) before I create the DAO object? I have been able to create DAO objects on my localhost just by calling CRM_Core_DAO::executeQuery() without initializing the API, so I thought I didn't need to, but I want to make sure.

Also, what files do I need to import with require_once in order to create a DAO object? I use a DAO object in a hook_cron() function in my project and I'm getting "Can not create CRM_Core_DAO" errors. I was able to find "<module root>/CRM/Core/DAO.php", but is this the only file I would need to bring in or does it also depend on some other files?

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Using CRM_Core_DAO class with Drupal 5.x and CiviCRM 1.9
February 02, 2008, 06:02:40 pm

You dont need to call civicrm_initialize. Here is how we do all our scripts:


Code: [Select]
require_once '../civicrm.config.php';
require_once 'CRM/Core/Config.php';

$config =& CRM_Core_Config::singleton();

note the first require is relative, since the files are in the civicrm bin directory. if runnign within drupal, civicrm_initialize( ) is the easy way to do it and bypass the above lines (it basically does the above)

i dont know too much about drupal_cron to be more specific with what lines to code to add.

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

posco

  • I post occasionally
  • **
  • Posts: 49
  • Karma: 8
Re: Using CRM_Core_DAO class with Drupal 5.x and CiviCRM 1.9
February 02, 2008, 06:40:18 pm
Thanks. That fixed my problem!

For future reference you do need to call civicrm_initialize() when using the DAO object in hook_cron() functions. I suspect this is because the CiviCRM headers aren't called when Drupal runs its cron functions.

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • Using CRM_Core_DAO class with Drupal 5.x and CiviCRM 1.9

This forum was archived on 2017-11-26.