Call to undefined function db_query() 5

Drupal provides the function db_query() to interact with database.

This function is defined in includes/ file.

You have to include in your file to get db_query() working.

<?php include(“includes/”); ?>

However if you are trying to access drupal database from a non-drupal .php file then all you need to do is to include following lines at the top of your file.

require_once ‘./includes/’;

5 thoughts on “Call to undefined function db_query()

  1. Reply pavani Nov 9,2009 12:23 pm


    I am new to drupal created a module for that I need to execute database queries in a .php file in that module folder.

    I tried to implement the above code but I am getting a error that ./includes/ not found error.

    Can you help me out


  2. Reply Ajay Nov 9,2009 1:41 pm

    Can you check if you have this file ./includes/ ?
    Also could you check the path for the above file?

  3. Reply pavani Nov 10,2009 11:05 pm


    I have checked the path …
    since I cannot change the path in

    I changed the dir to the drupal installation directory from the modules folder and then included rather specifying the path at the require_once

    this worked…

    $drupal_path = “../”; // <—- change this one to fit yours
    require_once "./includes/";

    rather than
    require_once "../../../../includes/";

    thank you very much


  4. Reply ibrahim Mar 4,2010 5:07 pm

    I try to call function from drupal,s module file via standard ajax
    but i get this error:
    Call to undefined function db_query()
    also i set include statement for (,,..) and other data base file but it is not working
    please any help

  5. Reply bob Aug 17,2011 3:04 pm

    try to put the include code in a file situed in your root directory, because all files included in are included like that : ‘./includes/’

Leave a Reply