Jump to content

Getting info from 2 separate databases to display


thefreebielife

Recommended Posts

<?php
$con1 = mysql_connect('localhost');
mysql_select_db('test');

/**
* using default 'test' db
*/
$res1 = mysql_query("SELECT * FROM sales");
while ($row = mysql_fetch_row($res1)) {
    echo join(' | ', $row) . '<br>';
}
/**
* using table from 'test2' db
*/
$res2 = mysql_query("SELECT * FROM test2.city");         // specify db.table
while ($row = mysql_fetch_row($res2)) {
    echo join(' | ', $row) . '<br>';
}
?>

Same again, but with different logins (untested)

<?php
$con1 = mysql_connect('localhost','user1', 'pwd1');
mysql_select_db('test', $con1);

$con2 = mysql_connect('localhost','user2', 'pwd2');
mysql_select_db('test2', $con2);


/**
* using  'test' db
*/
$res1 = mysql_db_query("test", "SELECT * FROM baagriddata");
while ($row = mysql_fetch_row($res1)) {
    echo join(' | ', $row) . '<br>';
}
/**
* using table from 'test2' db
*/
$res2 = mysql_db_query("test2", "SELECT * FROM city");
while ($row = mysql_fetch_row($res2)) {
    echo join(' | ', $row) . '<br>';
}
?>

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.