View Full Version : Connecting to mysql but not connecting

04-04-2007, 04:06 PM
I dont know if technically this should be a php or a mysql problem but I dont want to cross-post.
I'm including a database connection file from another website. eg. include(http://domain1.com/dbc.inc.php) is in my page on domain2.com - now I tihnk both these domains are on the same server but I tihnk thats probably irrelevant.
The issue is that the file includes and runs perfectly, it says it has successfully established a mysql connection, however when I try to use that connection it says there is no connection... or more correction it says
Warning: mysql_query(): Access denied for user 'nobody'@'localhost' (using password: NO) in ...
Warning: mysql_query(): A link to the server could not be established in...

which usually means, you forgot to include your db script dummy. now I could just create 'dummy' pages that just have include(domain1.com/pagename.php) and that would work because we do a similar thing on other pages to grab the content.
I just dont understand why the connection that is created isnt available to the page.

04-04-2007, 04:23 PM
I am guessing that this include file contains the actual connection and db selection code and that it is the one that outputs the success messages?

Including a file through the http protocol causes a separate "session" on the server to run and parse the .php file, just as through you browsed to the URL with a browser. When the code in that file gets to the end, it releases any resources, including mysql links.

04-04-2007, 04:35 PM
If the target server interprets the target file as PHP code, variables may be passed to the included file using a URL request string as used with HTTP GET. This is not strictly speaking the same thing as including the file and having it inherit the parent file's variable scope; the script is actually being run on the remote server and the result is then being included into the local script.


04-04-2007, 04:39 PM


04-04-2007, 04:45 PM
I got around it - looks like they are on the same server and I just used the same connect file with 'localhost' as the address and it worked

04-04-2007, 09:58 PM
I just added the dots so that the forum would let me post the quote from the PHP manual.