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

Recommended Answers

All 4 Replies

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.

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

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.

% 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.

Thank you for your kind information

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.