Turns out my syntax was wrong. All is well, I fixed it by establishing my own connection using the information in wp-config.php!
That fixed it! Thank you.
The second method (using strpos to find the page name in the URL) would almost certainly work for me, but $pagenow is empty. Were you just using that as an example, or is that actually supposed to be a wordpress global var?