tags:

views:

43

answers:

4

I am trying to customize a Drupal 6.x module. The original module does not make any calls to the database, but the customized version needs to pull some data from the database. The query should take place with an AJAX call. So I am trying to make a data provider to receive the call, query the database, and return the result (some json).

For the data provider I need a link to the database, but I don't want to create the link in the script, rather I want to find the script where db connection values are stored and include that file. But I don't seem to have any success in finding the file. Where is it located in a typical Drupal installation?

P.S. I don't want to make this into a Drupal module and follow all the conventions to create _hook(), ... functions. I want to make it straight forward and old-school.

+2  A: 

"P.S. I don't want to make this into a Drupal module and follow all the conventions to create _hook(), ... functions. I want to make it straight forward and old-school."

Why? This is the -easiest- way to do it and you can still define the external db connection there and utilize the Drupal database layer, and you can do this from within the module you are customizing.

If you are not utilizing an external database (not Drupal) then you can just use the Database API.

http://api.drupal.org/api/group/database/6

Additional settings can be stored in settings.php but since you are customizing a module, I would have it right within the module so you don't have to hunt it down later.

Kevin
Maybe easiest if you already have a working knowledge of the framework. I'm not familiar with it, and what I'm trying to achieve is quite trivial.
Majid
A: 

Database settings should be in sites/default/settings.php.

ceejayoz
Thanks. Looks they cannot do ANYTHING straightforward, now I should get the values out of a url!
Majid
Your insistence on doing this the hard way is why things don't seem straightforward, if you ask me.
ceejayoz
+7  A: 

An easy way if you are calling this file directly is to bootstrap drupal. For example you can do the following:

<?php
// Bootstrap Drupal
require 'includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
?>

This will allow you to access the full range of drupal API's including db_query(). For your use you may want to pass just DRUPAL_BOOTSTRAP_DATABASE instead of DRUPAL_BOOTSTRAP_FULL into drupal_boostrap(). See http://api.drupal.org/api/function/drupal_bootstrap/6 for reference.

bkildow
This looks simple and I'll try it. Thanks.
Majid
The code needs to be placed in a PHP file that is in the Drupal root directory; if you place it in a different directory, the path used for the bootstrap file needs to be changed.The file needs then to be invoked independently from Drupal.
kiamlaluno
A: 

You can add your second database to the drupal settings file and switch back and forth when needed. Look here: How to connect to multiple databases within Drupal

Eric M

related questions