How do I access the database from a stand-alone PHP script? I have problems to define the right path to the root and bootstrap data in php. 

My structure (Windows) looks like the following.


C:\xmapp\


htdocs\


testdrupal\


test.php 


includes\


bootstrap.inc

sites\


default\


settings.php





The content of the test.php file is the following.

&lt;?php

  chdir('C:\xampp\htdocs\testdrupal\');
  // Bootstrap Drupal up through the database phase.
  include_once('./includes/bootstrap.inc');
  drupal_bootstrap(DRUPAL_BOOTSTRAP_DATABASE);
?&gt; 


When I run it, I get the following error. 


  Parse error: syntax error, unexpected '/' in C:\xampp\htdocs\testdrupal\test.php


What am I doing wrong?
Check the first line (where you have ..testdrupal\');

The \ before the ' is escaping the ' so it's as if it's not there (sorry, it's tricky to explain without my morning coffee).

With the character escaped, the line is being read as follows:

chdir('C:\xampp\htdocs\testdrupal'./includes/bootstrap.inc');

Which is where your error is most likely coming from.

Try changing the first line to the following:

chdir('C:\xampp\htdocs\testdrupal\\');


The extra \ means that you are escaping the following character so the line will be read the way you want it to be.

There's a quick explanation of escape characters here.