NYCPHP Meetup

NYPHP.org

[nycphp-talk] different sites, one database

Henry Ponce henry at beewh.com
Wed Jul 13 11:46:08 EDT 2005


On Wednesday 13 July 2005 12:33, Adam Fields wrote:
> On Wed, Jul 13, 2005 at 12:15:17PM -0300, Henry Ponce wrote:
> > Well, now I need to connect to a mysql database on site1.com that holds
> > information that is usefull and needed for most sites. I need to do this
> > on scripts that run on site2.com and site3.com.
> >
> > How can I connect to the mysql database on site1.com, when I am running a
> > script on site2.com or site3.com?
> >
> > I can't use "localhost" as the server in the mysql_connect() function in
> > the scripts on site2.com or site3.com, because I would be connecting to
> > the mysql database, on each site, which I understand.
>
> That depends. Are these actually the same database with different
> logins? That's probably the case, in which case you >can< use
> localhost, and just change the login info.
>
> If they're different databases, you should be able to substitute
> "site1.com" or "site2.com" or whatever for "localhost", assuming the
> db is set up to listen on ips other than 127.0.0.1 (which it probably
> shouldn't be, but probably is).
>
> Do site1.com, site2.com, etc... all resolve to the same IP address?

They do. They all resolve the same IP address.

And they are different databases. I tried substituting "localhost" for 
"site1.com" and got an error:

Warning: mysql_connect(): Access denied for user: 'henry at site1.com' (Using 
password: YES) in /home/httpd/vhosts/site2.com/httpdocs/mysql_test.php on 
line 22

Thanx...
Henry



More information about the talk mailing list