Vanessa Marchelli
Vanessa Marchelli

Reputation: 103

¿Can i set in Mysql the use of two different data base at the same time?

I have a site in a server, and the data base in other server.

My site was connected with two differnt data bases at the same time without any problem, but when I change the server's data base I had a problem, my site did not recognice two conecctions.

The solution that i found was, set true on the parameter "new link" in mysql_connect function, as the same:

$link_web = mysql_connect($host_web,$user_web,$pass_web, true)

But i have a question about other possible solution.

Could i solve the problem, setted sql.safe-mode as 'on' in my php.ini? or is possible solve this problem whiht another way without change the source code?

Upvotes: 0

Views: 73

Answers (1)

symcbean
symcbean

Reputation: 48387

There are lots of ways you could fool PHP into creating separate connections - but they are, at best, redundant. You are relying on facts about your data access (the database you are connecting to) persisting in the database session. That's not a good starting point for writing large, complex applications where you cannot always be certain of the sequence of events. A neater solution is to still call mysql_connect() twice (in case the databases are ever split across separate hosts) have your code treat the returned handles as 2 seperate values and specify in your sql what database the DML applies to:

SELECT *
FROM yourdatabase.yourtable;

Upvotes: 1

Related Questions