943,746 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 717
  • PHP RSS
Sep 27th, 2009
0

Php mysql connect

Expand Post »
Hai friends,
I had a main web site and a number of 15 ( also increasing ) child websites. I had a master database in my main website. Now I need to connect main database from the child websites. I had a code to connect the database from main website that is...

mysql_connect("localhost", "user_name","password") or die(mysql_error());
mysql_select_db("database_name") or die(mysql_error());

I tried this code on child website. But access denied error showing. I already set all privileges to the above user . I tried this code


mysql_connect("mydomain.com", "user_name","password") or die(mysql_error());
mysql_select_db("database_name") or die(mysql_error());

I also tried www.mydomain.com, http://mydomain.com, ip address of my domain insted of "localhost" . But cant connect...


Please give me a help in the above problem.
Thanks in advance
Rajeesh
Reputation Points: 10
Solved Threads: 0
Posting Whiz in Training
rajeesh_rsn is offline Offline
265 posts
since Sep 2008
Sep 27th, 2009
0

Re: Php mysql connect

Do you use shared web hosting?
Most shared hosting limit mysql connection from localhost only due to security reason. You cant connect to mysql on a shared hosting from different host.

Ask your hosting provider whether they provide "Remote MySQL", or move all of your website to one single server.
Reputation Points: 10
Solved Threads: 7
Light Poster
farhan386 is offline Offline
44 posts
since Jul 2008
Sep 27th, 2009
0

Re: Php mysql connect

Thanks for your kind advice.
I solved the problem using Remote MySQL, as you said i just added my host name in to remote mysql like XXX.XX.XXX.%.

If you don't mind please let me know for what "%" is using. Is there is any security issue if I enable remote MySQL

Once again thanks for your support
Rajeesh




Click to Expand / Collapse  Quote originally posted by farhan386 ...
Do you use shared web hosting?
Most shared hosting limit mysql connection from localhost only due to security reason. You cant connect to mysql on a shared hosting from different host.

Ask your hosting provider whether they provide "Remote MySQL", or move all of your website to one single server.
Reputation Points: 10
Solved Threads: 0
Posting Whiz in Training
rajeesh_rsn is offline Offline
265 posts
since Sep 2008
Sep 27th, 2009
0

Re: Php mysql connect

% mean "from any host"

user1@localhost mean "user1 who came from localhost only"
user1@% mean "user1 who came from anywhere"

disabling remote mysql is the safest option, since you can sure that only script resides on your own server are allowed to access your database.

By enabling remote mysql with wildcard (the %), your database can be accessed (and of course, brute forced) from anywhere.
Reputation Points: 10
Solved Threads: 7
Light Poster
farhan386 is offline Offline
44 posts
since Jul 2008
Sep 28th, 2009
0

Re: Php mysql connect

Thank you for your kind information
Reputation Points: 10
Solved Threads: 0
Posting Whiz in Training
rajeesh_rsn is offline Offline
265 posts
since Sep 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Problem with changing hosting server
Next Thread in PHP Forum Timeline: Iframe and virus





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC