I have a php script that I'm trying to invoke the drupal bootstrap on so I can use Drupal database functions. As a side note, this
page is rendered via ajax call from a custom module I'm writing called "drm".
The php script is located at modules/drm/tags.php
tags.php/
require_once '../../../../includes/bootstrap.inc';
//drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
print("GOT HERE");
// query for image tags
$results = db_query("
SELECT
tag_id,tagname,imagewidth,imageheight
FROM
media_tag
ORDER BY
tagname
");
To trouble shooot, I open up http://localhost/sites/all/modules/drm/tags.php in a web browser.
PHP finds the bootstrap include fine and prints "GOT HERE" indicating the path is correct. For example, if I change the bootstrap.inc path, the "GOT HERE" message disappears indicating it cannot find the file.
The path is correct, but the drupal_bootstrap call is not working. When I uncomment out the drupal_bootstrap call, the GOT HERE message disappears. I'm not sure why this call isn't working. Can anyone help.
Thanks
Comments
Here's the bootstrap call in
Here's the bootstrap call in Pro Drupal Development book
I also think that using relative path for the require_once is not the safest idea
Let me know if it helps
Finds the file, but call still not working
Thanks,
I changed the code to be:
$path='c:\Program Files\Apache Software Foundation\htdocs"';
chdir($path);
include_once('./includes/bootstrap.inc');
Again, it finds the file, but errors out when trying to bootstrap.
I'll keep you posted as I stumble across stuff.
I'm so glad you asked this
I'm so glad you asked this question--am hoping someone can provide a better answer, but here's what I do for my AJAX files. I put the .php file in the top level of the drupal tree and use the following lines of code to do the bootstrap:
but there must be a better way, since having those files at the top level of Drupal is not the right place for them. But I know this works for us.
or you can chdir() to drupal
or you can chdir() to drupal root directory before the include.. Edited: damm late.. have you tried to bootstrap only the database stage?
Thanks xcf33 - Got it working!
Got it working, but had to use relative paths. I will probably play around with this later, but this works for now.
My tags.php file is located at sites/all/modules/drm/tags.php.
The following code can be used to bootstrap the database layer from tags.php:
chdir('../../../../');
include_once('./includes/bootstrap.inc');
drupal_bootstrap(DRUPAL_BOOTSTRAP_DATABASE);