aQ Posted July 2, 2007 Share Posted July 2, 2007 Hello! I am trying to post some info from a form, and into two databases. I have one of my mysql connections in a config file, and the other one in the file I am posting from. It is something like this: <?php include(config.php); //send something to the first database mysql_query("INSERT INTO ...."); // And connect to the other db: $xconnect = mysql_connect("x", "x", "x"); mysql_select_db("x", $xconnect); // Then send info to the second db: mysql_query("INSERT INTO ...."); ?> Is this a good way to do it? I don't feel that it works correct, I get some errors and such.... Can you help me? Link to comment https://forums.phpfreaks.com/topic/58107-solved-send-information-to-different-databases/ Share on other sites More sharing options...
vbnullchar Posted July 2, 2007 Share Posted July 2, 2007 from http://www.php.net/manual/en/function.mysql-connect.php specify the link indentifier <?php $link1 = mysql_connect('example.com:3307', 'mysql_user', 'mysql_password'); $link2 = mysql_connect('example2.com:3307', 'mysql_user', 'mysql_password'); mysql_select_db('foo', $link1); mysql_select_db('foo2', $link2); ?> Link to comment https://forums.phpfreaks.com/topic/58107-solved-send-information-to-different-databases/#findComment-288125 Share on other sites More sharing options...
aQ Posted July 2, 2007 Author Share Posted July 2, 2007 So all queries written after I select new db will be connected to that db-connection? Link to comment https://forums.phpfreaks.com/topic/58107-solved-send-information-to-different-databases/#findComment-288129 Share on other sites More sharing options...
vbnullchar Posted July 2, 2007 Share Posted July 2, 2007 you need to specify the link id to your query also. resource mysql_query ( string $query [, resource $link_identifier] ) ex. mysql_query("select * from employees",$link_id); Link to comment https://forums.phpfreaks.com/topic/58107-solved-send-information-to-different-databases/#findComment-288135 Share on other sites More sharing options...
aQ Posted July 2, 2007 Author Share Posted July 2, 2007 Ok, that's fine. Can you tell me how to print out the highest id available in a table? Link to comment https://forums.phpfreaks.com/topic/58107-solved-send-information-to-different-databases/#findComment-288148 Share on other sites More sharing options...
corillo181 Posted July 2, 2007 Share Posted July 2, 2007 you cna use a ORDER BY id DESC limit 1 this will print out the highest id Link to comment https://forums.phpfreaks.com/topic/58107-solved-send-information-to-different-databases/#findComment-288152 Share on other sites More sharing options...
vbnullchar Posted July 2, 2007 Share Posted July 2, 2007 SELECT max(id) FROM table; Link to comment https://forums.phpfreaks.com/topic/58107-solved-send-information-to-different-databases/#findComment-288156 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.