Smart questions
Smart answers
Smart people
Join Tek-Tips Forums

Member Login

Remember Me
Forgot Password?
Join Us!

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.
Jobs from Indeed

Link To This Forum!

Partner Button
Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Use PHP to connect to MySQL database from a different host

darryncooke (TechnicalUser) (OP)
20 Aug 11 23:48
So i have site A (Wordpress blog as CMS) on one shared host and Site B (wordpress blog) on another shared host.

I am trying to connect from A to B MySQL using php but my script wont connect.

Script works fine if I run it from B. So I am guessing its a permissions issue with MySQL. How do I allow domain A access to B through PHPMYADMIN as that's all Godaddy affords me.

BTW A is on one host and B is on Godaddy, not that it matters.

Darryn Cooke | Marketing and Creative Services

jpadie (TechnicalUser)
21 Aug 11 6:54
you can do it in plain mysql but you may consider that to be insecure.

on box B insert this sql to the panel in phpmyadmin on Box B



This assumes you want box a to have full rights.  if only limited rights are required then change the ALL statement as required.

of course you need to make sure that port 3306 (the mysql default port) is on Box B.

the, more secure, alternative is to ssh from box B to box A and do a port redirect over the tunnel.  

for example, run this code on Box A


ssh -N -f -L {username}
[type password]

you can reference Box B by IP address or domain name.

then attach to the mysql database as if it were on localhost.


mysql_connect ('', $user, $password);

If the connection is flaky or the boxes go frequently down then you will want to set up key based ssh connection and write a cron job that tests for the presence of the link every few seconds and re-establishes it if there is a problem.   or perhaps autossh.  That is beyond the scope of this forum.
darryncooke (TechnicalUser) (OP)
21 Aug 11 13:53
thanks ill give both a go - security is not a huge deal. its just one website wanting to pull blog feed for their respective author.

Darryn Cooke | Marketing and Creative Services

lgarner (IS/IT--Management)
22 Aug 11 17:30
"BTW A is on one host and B is on Godaddy, not that it matters."

It might, especially for the part about making sure port 3306 is available.   
jpadie (TechnicalUser)
22 Aug 11 17:38

but a rackspace US virtual server is only a dollar or two a month more expensive.  and for that you have full root access.  no brainer.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Back To Forum

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close