A PHP program that connects two different MYSQL databases_PHP tutorial

WBOY
Release: 2016-07-21 16:03:59
Original
886 people have browsed it

  
    echo "Connecting as mysql
n";  
    $connection1 = mysql_connect('localhost', 'mysql', '') or die($php_errormsg);  
    echo "connection1 is $connection1
n";  
    echo "Selecting test for mysql user
n";  
    mysql_select_db('test', $connection1) or @die("Error " . $php_errormsg . mysql_error());  
    echo "Connection as joyce
n";  
    $connection2 = mysql_connect('localhost', 'joyce', '') or die($php_errormsg);  
    echo "connection2 is $connection2
n";  
    echo "Selecting books for joyce user
n";  
    $db2 = mysql_select_db('techbizbookguide', $connection2) or die(mysql_error());  
    $query1 = "select foo from test";  
    $query2 = "select title, authorFirst, authorLast from bookinfo";  
    echo "Querying test
n";  
    $users = mysql_query($query1, $connection1) or die(mysql_error());  
    echo "Querying books
n";  
    $books = mysql_query($query2, $connection2) or die(mysql_error());  
    echo "Foos from test
n";  
    while (list($foo) = mysql_fetch_row($users)){  
        echo $foo, "
n";  
    }  
    echo "Books in techbizbookguide
n";  
    while (list($title, $authorFirst, $authorLast) = mysql_fetch_row($books)){  
        //Use trim in case we have a book by "Madonna" or "Prince" or...  
        echo $title, ' by ', trim($authorFirst . ' ' . $authorLast), "
n";  
    }  
?>  
  

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/316073.htmlTechArticleHTMLBODY BGCOLOR=FFFFFF ?php echo Connecting as mysqlBRn; $connection1 = mysql_connect('localhost', 'mysql', '') or die($php_errormsg); echo connection1 is $connection1BRn; echo S...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template