For testing purposes, or for executing Drupal-related operations but from a PHP script that runs outside of Drupal, I often create independent PHP files that are not meant to be Drupal modules but still require access to Drupal’s database, functions and modules.
Using the function drupal_bootstrap, located within includes/bootstrap.inc, your script can load Drupal and make all of Drupal’s functionality accessible to your script.
For access to the Drupal database layer only:
For access to all modules and functions:
Here is an example PHP script that loads Drupal in order to gain access to a Drupal node:
//set the working directory to your Drupal 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 ''; print_r(node_load(12)); print '';