Call to undefined function db_query()
Ajay on January 31st, 2008Drupal provides the function db_query() to interact with database.
This function is defined in includes/database.inc file.
You have to include database.inc in your file to get db_query() working.
<?php include(“includes/database.inc”); ?>
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/bootstrap.inc’;
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
Hi,
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/cahce.inc not found error.
Can you help me out
Regards,
Pavani
[Reply]
Can you check if you have this file ./includes/cahce.inc ?
Also could you check the path for the above file?
[Reply]
pavani Reply:
November 10th, 2009 at 11:05 pm
@Ajay,
I have checked the path …
since I cannot change the path in bootstrap.inc
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
chdir($drupal_path);
chdir($drupal_path);
chdir($drupal_path);
chdir($drupal_path);
require_once "./includes/bootstrap.inc";
rather than
require_once "../../../../includes/bootstrap.inc";
thank you very much
Regards,
Pavani
[Reply]
Hi:
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 (database.inc,database.sql.inc,..) and other data base file but it is not working
please any help
[Reply]