一个连接两个不同MYSQL数据库的PHP程序

2016-01-29 14:52 49 1 收藏

一个连接两个不同MYSQL数据库的PHP程序,一个连接两个不同MYSQL数据库的PHP程序

【 tulaoshi.com - PHP 】

  <HTML<BODY BGCOLOR=FFFFFF  
<?php  
    echo "Connecting as mysql<BRn";  
    $connection1 = mysql_connect('localhost', 'mysql', '') or die($php_errormsg);  
    echo "connection1 is $connection1<BRn";  
    echo "Selecting test for mysql user<BRn";  
    mysql_select_db('test', $connection1) or @die("Error " . $php_errormsg . mysql_error());  
    echo "Connection as joyce<BRn";  
    $connection2 = mysql_connect('localhost', 'joyce', '') or die($php_errormsg);  
    echo "connection2 is $connection2<BRn";  
    echo "Selecting books for joyce user<BRn";  
    $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<BRn";  
    $users = mysql_query($query1, $connection1) or die(mysql_error());  
    echo "Querying books<BRn";  
    $books = mysql_query($query2, $connection2) or die(mysql_error());  
    echo "Foos from test<BRn";  
    while (list($foo) = mysql_fetch_row($users)){  
        echo $foo, "<BRn";  
    }  
    echo "Books in techbizbookguide<BRn";  
    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), "<BRn";  
    }  
?  
</BODY</HTML   

来源:http://www.tulaoshi.com/n/20160129/1494559.html

延伸阅读
标签: MySQL mysql数据库
使用MYSQL进行数据库备份,又很正规的数据库备份方法,同其他的数据库服务器有相同的概念,但有没有想过,MySQL会有更简捷的使用文件目录的备份方法,而且又快有好。 一、数据备份捷径 因为这个方法没有得到官方正式文档的验证,我们暂称为试验吧。 目的:备份hostA主机中一个mysql数据库TestA,并恢复到到hostB机中 试验环境: 操作...
标签: ASP
  程序实现功能:两个数据表的数据分页显示 最近我遇到一个比较少见的需求,不知大家是否也有遇到过,说出来与大家分享. 客户需求:两部分数据,分别来自不同位置的两个数据库中的两个表,定义为数据库DB1和DB2,表Table1和Tabel2,要将这两个表数据分别在页面的上半部分和下半部分显示,并且用同一个分页码,如第一部分数据不够,将用第二部分数...
标签: ASP
       To assist in interfacing with databases. This script can format variables and return SQL formats. Such as double quoting apposterphies and surrounding strings with quotes, Returning NULL for invalid data types, trimming strings so they do not exceed maximum lengths. This also ha...
标签: PHP
  <?php // // SourceForge: Breaking Down the Barriers to Open Source Development // Copyright 1999-2000 (c) The SourceForge Crew // http://sourceforge.net // // $Id: database.php,v 1.6 2000/04/11 14:17:13 cvs Exp $ // // /etc/local.inc includes the machine specific database connect info function db_c...
Function CreateNormalDB(strPathName As String) As Boolean On Error GoTo Exit_ERR Dim wrkDefault As Workspace Dim NewDB As Database CreateNormalDB = False Set wrkDefault = DBEngine.Workspaces(0) If Dir(strPathName) < "" Then Kill strPathName Set NewDB = wrkDefault.CreateDatabase(strPathName, dbLangGeneral) NewDB.Cl...

经验教程

520

收藏

84
微博分享 QQ分享 QQ空间 手机页面 收藏网站 回到头部