Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Senior Coder NancyJ's Avatar
    Join Date
    Feb 2005
    Location
    Bradford, UK
    Posts
    3,174
    Thanks
    19
    Thanked 66 Times in 65 Posts

    Connecting to mysql but not connecting

    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
    Code:
    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.

  • #2
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,149
    Thanks
    2
    Thanked 333 Times in 325 Posts
    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.
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #3
    Senior Coder
    Join Date
    Aug 2003
    Location
    One step ahead of you.
    Posts
    2,815
    Thanks
    0
    Thanked 3 Times in 3 Posts
    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.
    .....
    I'm not sure if this was any help, but I hope it didn't make you stupider.

    Experience is something you get just after you really need it.
    PHP Installation Guide Feedback welcome.

  • #4
    Senior Coder NancyJ's Avatar
    Join Date
    Feb 2005
    Location
    Bradford, UK
    Posts
    3,174
    Thanks
    19
    Thanked 66 Times in 65 Posts
    Quote Originally Posted by marek_mar View Post
    .....
    ?????

  • #5
    Senior Coder NancyJ's Avatar
    Join Date
    Feb 2005
    Location
    Bradford, UK
    Posts
    3,174
    Thanks
    19
    Thanked 66 Times in 65 Posts
    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

  • #6
    Senior Coder
    Join Date
    Aug 2003
    Location
    One step ahead of you.
    Posts
    2,815
    Thanks
    0
    Thanked 3 Times in 3 Posts
    I just added the dots so that the forum would let me post the quote from the PHP manual.
    I'm not sure if this was any help, but I hope it didn't make you stupider.

    Experience is something you get just after you really need it.
    PHP Installation Guide Feedback welcome.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •