Connect to Drupal database from outside Drupal

I have found several examples that suggest the code below should display the results of a database query.

$result = db_query('SELECT title FROM {node}');
print_r ($result);

Drupal is installed in a sub-folder off public_html, mmclone1. I have checked the path with getcwd().

However when the code is run it displays the website with a ‘Page Not Found message for mmclone1/test1.php where test1.php is the file name of the code above.

I must have missed the point on something here !

Drupal version: