Forum Moderators: coopster
If the databases are in the same server, i can use simple script:
create temporary table table_union select * from database1.table;
insert into table_union select from * from database2.table;
then use some code select to show the content of temporary table table_union (very fast because temporary table created in memory)
but, now i have to deal with 2 database in 2 diff. server. Is there any chance that i can use some same code like the one use temporary table? i realise that one of the solution maybe is by using the mysql_dump. but, it means i have to import and make table on the server.
i want to find the solution for the problem by connecting directly to diff. db on diff. server on one script. so, the solution have to deal with the connection.
Can anyone help me? THanks for support.
What i really need is the solution in php, which connect me to 2 db. BTW, how to colate the data in php? do i have to save data from db1 to some variable first and combine it with data from db2?
Can u give me some example?
What you need to do is connect using mysql_connect [ca3.php.net] to one server, pull the data you need into an array, possibly, and then do the same on the other server.
When you connect to the seecond server you could close the original connection and connect to the new one, keeping it as logical as possible. When you grab the results from the second server you could use the already loaded array to add too.
This depends utterly on whether the data matches or you need only results that do not appear in the array already or you just need to add data to the existing array elements. I couldn't really tell you what exactly you need to do.
That is the rough outline of the process. Start by connecting to the first server and loading an array. Once that is working analyze the differences in data on the second and see what is the best way to merge your results. Then start on the merging process.
That should probably get you rolling, after all, it's your degree, not mine. ;)
You can successfully use multiple databases over a local or a remote connection in the same statement when they share the same resource link_identifier:
PHP
mysql_query() [php.net]sends a query to the currently active database on the server that's associated with the specified link identifier. If link_identifier isn't specified, the last opened link is assumed. If no link is open, the function tries to establish a link as if mysql_connect() [php.net] was called with no arguments, and use it.
As you should know, each MySQL connection is associated to a link identifier. That happens because
mysql_connect returns the resource link identifier on success, or FALSE on failure. Therefore if we establish two connections, each to a different server, and our query statement is only capable of using one connection via it's resource link identifier, we cannot use the databases on the other link.
In msg Step 5 - you could put the data into an array instead of displaying it by changing the display loop
while ($row = mysql_fetch_array($query)) {
echo "<p>",$row['id'],": ",$row['manufacturer'];
}
to
while ($row = mysql_fetch_array($query)) {
$myarr[] = array($row['id'],$row['manufacturer']);
}