MySQL Forums
Forum List  »  PHP

Creating a table on another server based upon local table
Posted by: Brian Schonecker
Date: March 28, 2006 12:20PM

I'm trying to create a table of summary data on a server that is separate from the data I'm trying to summarize. I can connect to both of them via PHP but I'm having trouble doing the following pseudo-code query:

create table Server1.Database1.Table1 (select * from Server2.Database2.Table1)

There's more to the picture than that but that's the overall objective. Here's my PHP/MySQLi code that I've written.

<?php


// Server1 database name: remote table name: weblog
// Server2 database name: home table name: summary

$HomeServer_1_USER='root1';
$HomeServer_1_PASS='pass1';
$HomeServer_1_IP='127.0.0.1';


$HomeServer_USER = 'root2';
$HomeServer_IP = 'external_IP.domain.com';
$HomeServer_PASS = 'pass2';


$RemoteServer = mysqli_connect($RemoteServer_IP, $RemoteServer_USER, $RemoteServer_PASS) or die("\nError: " . mysqli_error($RemoteServer) . "\n");
$HomeServer = mysqli_connect($HomeServer_IP, $HomeServer_USER, $HomeServer_PASS) or die("\nError: " . mysqli_error($HomeServer) . "\n");


mysqli_select_db($RemoteServer, 'weblog') or die("\nError: " . mysqli_error($RemoteServer) . "\n");

$sql = 'create table \'home\'.\'summary\' (select * from remote.weblog group by IP_Address)';
$create_table = mysqli_query($RemoteServer, $sql) or die("\nError: " . mysqli_error($RemoteServer) . "\n");


mysqli_close($RemoteServer);
mysqli_close($HomeServer);

php>


A couple of questions:

Which connection (if any) knows about databases on the OTHER server?
Do I need a "use <database>" on one of the connections to tell it to use the database on the other server/connection?
Can this be done?


Thanks, Brian

Options: ReplyQuote


Subject
Written By
Posted
Creating a table on another server based upon local table
March 28, 2006 12:20PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.