Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #2462

Re: Copying data between databases

From "Álvaro G. Vicario" <alvaro.NOSPAMTHANX@demogracia.com.invalid>
Newsgroups comp.lang.php
Subject Re: Copying data between databases
Date 2011-07-07 08:28 +0200
Organization http://alvaro.es/
Message-ID <iv3jmi$27t$1@dont-email.me> (permalink)
References <lOaRp.57779$8G4.34016@newsfe17.iad>

Show all headers | View raw


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
--

Back to comp.lang.php | Previous | Next — Previous in thread | Find similar | Unroll thread


Thread

Copying data between databases "Sloan" <sloan@sloansweb.com> - 2011-07-06 23:41 -0500
  Re: Copying data between databases Mick Gurling <nospam@myemail.net> - 2011-07-07 04:51 +0000
    Re: Copying data between databases "Sloan" <sloan@sloansweb.com> - 2011-07-07 00:00 -0500
      Re: Copying data between databases The Natural Philosopher <tnp@invalid.invalid> - 2011-07-07 07:09 +0100
  Re: Copying data between databases The Natural Philosopher <tnp@invalid.invalid> - 2011-07-07 05:56 +0100
  Re: Copying data between databases "Álvaro G. Vicario" <alvaro.NOSPAMTHANX@demogracia.com.invalid> - 2011-07-07 08:28 +0200

csiph-web