Jump to content

using PHP to query a DB and dump into another??


acook

Recommended Posts

Would it be possible to have a PHP script that would query one DB (Sybase) and dump the results into another DB (mySQL)?  I've already got the query written and as it is right now, it just outputs the results by using:

 

echo"whatever results";

 

Is it fairly simple to take those same results and drop them into the new DB?  Also, is there a way to have this happen every 5 minutes?  I'm assuming I'd have to put a refresh script (like javascript) somewhere on the page as the script wouldn't run unless it was invoked.  Is that right?  Thanks!!

Yes, it's possible; just use the functions as you would in any other application.  Query one database, assemble a valid query for the other database, and execute it.

 

No, this program won't run by itself unless you set up a crontab entry or your own little daemon.  Or set it running in the background and put a sleep function in an infinite loop.

Yes, it's possible; just use the functions as you would in any other application.  Query one database, assemble a valid query for the other database, and execute it.

 

I guess the problem I'm running into is the dumping of the results into another DB.  I've already got all of my results in an array.  Do I just create another query like:

 

INSERT INTO blah $value1

 

Or something similar to that?

Sure, you can do that.  You don't have to put it in an array; you can assemble the query directly.

 


// Connect to dbs, query Sybase.

// Read data and assemble query:
$mysql_insert_query = 'INSERT INTO mytable VALUES ';
while ($row = sybase_fetch_row($result)) $mysql_insert_query(vsprintf("('%s','%s','%s','%s')", $row));

// Execute query:
mysql_query($mysql_insert_query);

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.