FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Copying data between databases
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: Copying data between databases [message #174782 is a reply to message #174777] Thu, 07 July 2011 06:28 Go to previous message
alvaro.NOSPAMTHANX is currently offline  alvaro.NOSPAMTHANX
Messages: 277
Registered: September 2010
Karma:
Senior Member
El 07/07/2011 6:41, Sloan escribió/wrote:
> I'm a bit new to PHP, but have been programming in other languages for
> quite a while. I'm pretty good a SQL, including MySQL.
>
> Here's my question:
>
> How do I connect to two databases (on the same server) to use an INSERT
> .... ON DUPLICATE KEY UPDATE in PHP were the source table in one
> database, and the destination table is in another?
>
> I've written the SQL statement with explicit db.table.field references
> so I think I can use mysql_query, but which link do I use, or how can I
> pass both links?

If they are on the same server, you don't need to open two links: you
just need a MySQL user that has the appropriate permissions.

The MySQL syntax would be something like this:

INSERT INTO target (foo, bar)
SELECT foo, bar
FROM source
WHERE id=314

And you are not restricted to mysql_query(), you have three or four
database libraries that can talk to MySQL. I've particularly found PDO
quite handy.


--
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://borrame.com
-- Mi web de humor satinado: http://www.demogracia.com
--
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: multi-page form
Next Topic: Earn $24.00 per Sign-Up!...Get Paided on all FREE MEMBERS!....{Sign-Up FREE}
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Tue Nov 26 04:13:47 GMT 2024

Total time taken to generate the page: 0.04581 seconds