For testing purposes, or for executing Drupal-related operationsbut from a PHP script that runs outside of Drupal, I often createindependent PHP files that are not meant to be Drupal modules butstill require access to Drupal’s database, functions andmodules.
Using the function drupal_bootstrap,located within includes/bootstrap.inc, your script can load Drupaland make all of Drupal’s functionality accessible to yourscript.
Common Usage
For access to the Drupal database layer only:
drupal_bootstrap(DRUPAL_BOOTSTRAP_DATABASE);
For access to all modules and functions:
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
Here is an example PHP script that loads Drupal in order to gainaccess to a Drupal node:
//set the working directory to yourDrupal root
chdir('/home/public_html/drupal/');
//require the bootstrap include
require_once './includes/bootstrap.inc';
//Load Drupal
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
//(loads everything, but doesn't render anything)
//display a node
print '<pre>';
print_r(node_load(12));
print '</pre>';
401

被折叠的 条评论
为什么被折叠?



