Last Updated: February 25, 2016
·
960
· ortuna

Drupal 6 bootstrap

Why you need it

Sometimes a Drupal install requires a script to do its dirty work or clean up. This is a quick way to add a script and run it with php myscript.php and interact with a Drupal 6 install.

Code
<?php

$_SERVER['SCRIPT_NAME'] = '/metadata.php';
$_SERVER['SCRIPT_FILENAME'] = '/metadata.php';
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
$_SERVER['REQUEST_METHOD'] = 'POST';
$_GET['q'] = '';
require_once './includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);

Now you can do some work! e.g.

$node = node_load($nid);
$node->title = "My new title";
node_save($node);