Search code examples
phpdatabasedrupal-7

Call to undefined function db_query


I have tried to configure a module that can get data from the database. I have used db_query to do this and every time I run the module I get the error:

Call to undefined function db_query.

I have been searching for months to find the answer to this and all I can find is that I need to bootstrap the page.

define('DRUPAL_ROOT', $_SERVER['DOCUMENT_ROOT']. $SERVER["REDIRECT_COMMUNITY_SUBSITE"]);
// Bootstrap Drupal up through the database phase.
require_once (DRUPAL_ROOT. '/includes/bootstrap.inc');
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);

However I am fairly sure I don't need to do this in a .module file but this seems to be the only thing that works.


Solution

  • How do you use your .module file?

    You can follow this tutorial to properly create a module:

    Creating modules - a tutorial: Drupal 7.x