Hello:
I have a problem selecting information from two different mysql databases. For an example I have created this to show what I'm trying to do.
In one database I have a table called 'News' and in another I have a table called 'AuthorsInfo'. How can I connect to these two databases and display 'AuthorsName' and 'AuthorsEmail' from the other database? The two tables have AuthorID in common.
Is this at all possible?
<?php
$con = mysql_connect('localhost', 'user1', 'pass1');
$db = mysql_select_db('news', $con);
$con2 = @mysql_connect('localhost', 'user2', 'pass2');
$db2 = @mysql_select_db('authors', $con2);
$sql ="SELECT NewsID, AuthorID, Info.AuthorsName, Info.AuthorsEmail, Title, Text
FROM News
LEFT JOIN AuthorsInfo AS Info ON (Info.AuthorID = News.AuthorID)
";
$result =mysql_query($sql,$con);
while ($row =mysql_fetch_array($result)){
echo "{$row ['NewsID']} - {$row ['AuthorsName']} - {$row ['AuthorsEmail']} - {$row ['Title']}<br>";
}
?>