PHP is connecting to the wrong MySQL database

Discussion in 'PHP' started by bscdesign.com, Feb 15, 2008.

  1. #1
    I just switched over to HostGator.com a few days ago and I moved my 2 biggest arcades over to their servers. One of them is the main domain and the other is an addon domain.

    I have 2 MySQL databases set up on the localhost. The main site and the addon domain are running the same CMS so they have the same set of folders and files needed for the script to run.

    When I connect to the database for my main site everything works fine. But when I try to connect to the database for my addon domain it still connects to the other database. I am using a username and password that doesn't have access to my main sites DB and a different database name. I can't figure this out and the Host Gator support and I have each done something that fixed it. But then when the day is over it is broken again.

    My site has been down for over 4 days. Please help.
     
    bscdesign.com, Feb 15, 2008 IP
  2. zerxer

    zerxer Peon

    Messages:
    368
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I do not see how it can possibly connect to another database if the database name you're passing the connect function is not the same as the one you don't want it to connect to. The only thing I can think of is maybe the 2nd site is including the wrong config file with the database information (if it even has one)? That would mean it's using the connection info for the other site.

    What do you mean though by you each did something that fixed it but then at the end of the day, it's broken again? I don't see how this can happen. Hmm..
     
    zerxer, Feb 15, 2008 IP
  3. bscdesign.com

    bscdesign.com Active Member

    Messages:
    681
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    58
    #3
    Well I messed with the config.php file a little and the site was up of almost 24 hours. But then at midnight the problem was back. Then a few hours ago their support edited my CMS's index.php file where it includes the config file. The changed the include path from "path/to/config.php" to "/home/username/public_html/path/to/config.php". The site was up for about 2 hours and then went down again at midnight.

    I read that this sometimes happens but non of the solutions worked ( http://us.php.net/manual/en/function.mysql-select-db.php#77690 ). The weirdest thing is that when I goto mysite.com/admin/ the connection is fine and it is including the same config.php file.
     
    bscdesign.com, Feb 15, 2008 IP
  4. zerxer

    zerxer Peon

    Messages:
    368
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Yeah, those solutions listed on the PHP.net page are only if you're connecting to multiple databases in the same script, not from two separate areas.

    I still cannot think how it can work for a little while but then stop working and also work when you're in your admin section. Sounds like witchcraft.. then again, it is almost 4 AM for me. :/

    Time to switch hosts? :p I used HostGator for awhile but found out that Surpass Hosting is much cheaper.. (and I love their support)
     
    zerxer, Feb 15, 2008 IP
  5. bscdesign.com

    bscdesign.com Active Member

    Messages:
    681
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    58
    #5
    I just paid for 6 months hosting. I have only been with them for less than a week and have no money left to go elsewhere other than return to dreamhost. Now that I think about it this might have happened 10 months ago when I started the site. It was fixed when I added the new database to a new host. All my sites had one database located at mysql.mysite.com. And it worked great except the fact that they had to many sites on my shared server and my sites were going down every other day.

    I am going to ask them if I am able to set up a DB like that.
     
    bscdesign.com, Feb 15, 2008 IP
  6. bscdesign.com

    bscdesign.com Active Member

    Messages:
    681
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    58
    #6
    I figured out the problem but now the support and I are trying to fix it. There is a problem with the main directory for my addon domain. I reuploaded all the files to a deeper folder ( test/ ) and everything is fine. Hope it is an easy fix now.
     
    bscdesign.com, Feb 15, 2008 IP