Access WordPress database outside of WordPress

In a nutshell there is no generic reliable way to load WordPress core from arbitrary file. Since core and extensions directories are independent from each other (they are co-located by default, not by necessity) only core configuration “knows” where extensions are, but not other way around.

In private code things like this just get hardcoded. In public code this is pretty much undoable properly.

If it’s not critical for you to modify core load process then custom URL is definitely way to go. Implemented via Rewrite API from scratch or as endpoint it will be reasonably reliable.