sooty2006 Posted February 5, 2008 Report Share Posted February 5, 2008 hi im making a website and on the frist mysql server i want user infomation and website stats etc...on the second mysql server i want to insert logs for when users login or other logged stuff!how can i use 2 mysql databases together!thanks all! Link to comment Share on other sites More sharing options...
Lulzim Posted February 5, 2008 Report Share Posted February 5, 2008 $conn1 = mysql_connect('mysqlserver1', '', ''); //connect to mysql server 1mysql_select_db('db1', $conn1)$conn2 = mysql_connect('mysqlserver2', '', '');//connect to mysql server 2mysql_select_db('db2', $conn2)$query1 = mysql_query("sql", $conn1); //query mysql server 1$query2 = mysql_query("sql", $conn2); //query mysql server 2 Link to comment Share on other sites More sharing options...
sooty2006 Posted February 5, 2008 Author Report Share Posted February 5, 2008 ok but will that cause any errors im just making sure is it completely safe to do that?be cause ive tryied it this way a few months back it creates errors sometimes! :)do i need to do this query for all statements or just the one i want to go to the (log) mysql serverINSERT INTO `database2`.`logs` (`id`, `to`, `from`, `msg`, `rea`, `sav`, `dat`, `cla`) VALUES (NULL, '23434', '34234', '3446fdgrwbgytgoreqbgytnhuiwnhoihneiohneyjjeytjyetj', 'no', 'no', NOW(), 'normal'); Link to comment Share on other sites More sharing options...
justsomeguy Posted February 5, 2008 Report Share Posted February 5, 2008 It doesn't create errors if you do it right. PHP doesn't just pop up with errors for no reason, if you see an error it's because you didn't do something right.Another question you need to ask yourself is why you need 2 database servers. Why can't you have the logs on the same server as everything else? Link to comment Share on other sites More sharing options...
sooty2006 Posted February 5, 2008 Author Report Share Posted February 5, 2008 because my host gave me 2 mysql servers i onli host one site on the server plus i need the database space the mysql server is holding alot of information i dont reli want it to get to the point were it carnt store anymre Link to comment Share on other sites More sharing options...
jhecht Posted February 5, 2008 Report Share Posted February 5, 2008 AS long as there's room on the server itself, your database can be as large as you really want it to be. And why not just use one database? It seems silly to do it on more than one(just complicates your life)I made a database class for php That I'm appending things to(parameter parsing, etc) if you like, i can post the code for it up here so you can look at it and use it. Much easier(all you would have to do is go $server1 = new Db('localhost,'user','pw','db1');$server2 = new Db('localhost','user','pw','db2'); And then just make subsequent calls to the query method. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now