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? Quote Link to comment 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); ?> Quote Link to comment 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? Quote Link to comment 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); Quote Link to comment 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? Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
vbnullchar Posted July 2, 2007 Share Posted July 2, 2007 SELECT max(id) FROM table; Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.