This is a discussion on Connecting to 2 Mysql database in the same script?? within the Coding Help forums, part of the Webmaster Help category; Basicly what I am trying to do here is tranfer infromation from one Mysql database 2 another via a PHP ...
| |||||||
| Register | Forum Rules | FAQ | Donate | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| Basicly what I am trying to do here is tranfer infromation from one Mysql database 2 another via a PHP script. The only thing about it is, that both Mysql database are on different servers, Here is the script I have got so far, but atm the secound connection isnt kicking in and its pulling info from the frist connect, I have tryed mysql_close() but still nothing. All the database selections and pass word and user name are correct also.Any idea? PHP Code: |
| |||||
| Basically, you need to create a second mysql connection and explicitly tell each mysql function which one to use. (I always supply the connection object anyway because I'm not sure which the functions will use if you don't specify one) E.g: Code: $con1 = mysql_connect( 'host','user','pass' ); $con2 = mysql_connect( 'host','user','pass' ); //Use first connection mysql_select_db( "db1", $con1 ); //Use second connection mysql_select_db( "db2", $con2 ); //Query first connection (db1) mysql_query( "SELECT etc....", $con1 ); //Query second connection (db2) mysql_query( "SELECT etc....", $con2 ); PS: Your array code really doesn't make any sense in the middle there. Array() creates, and returns an array. You don't wrap array assignments in Array(). |
| ||||
| Ok well I did what you suggected but it didnt work. I got this error and here is the code, I also change a small thing in one of the connections. Quote:
PHP Code: Last edited by Ciarán Mc Cann; 23-07-2007 at 03:37 PM. |
| |||||
| You've probably already seen it but you created the connections as "con" and "con2" whereas you are using "con" and "con1" in mysql_select_db. |
| ||||
| Now I got another problem I am now getting this erorr Quote:
|
| ||||
| No I havent, but I have been talking to admins of the system and they gave me a ip and told me to put % and the ip number and it should work. Something about a wildcard or somthing I anit sure what its all about. You probly cant help me anymore, thanks for the help anyway. Kind Regards Ciaran Mc Cann |
| |||||
| Do you not have access to phpMyAdmin or any other MySql access to a dump/export of the table and then import it on the other side. Would really be the quickest way.
__________________ PHP Code: |
| |||||
| Agree, just export the DB and import in into the new hosting!! |