连接两个不同MYSQL数据库的PHP程序
程序员文章站
2022-04-02 20:24:31
...
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";
}
?>
以上就介绍了连接两个不同MYSQL数据库的PHP程序,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。
推荐阅读
-
thinkphp3.x连接mysql数据库的方法(具体操作步骤)_php实例
-
Php连接及读取和写入mysql数据库的常用代码
-
php连接mysql数据库的类(接口实现)
-
insert-通过Php程序 像数据库插入内容时。在页面提交之后,mysql会有两个相同的数据 只有id不同
-
PHP数据库长连接mysql_pconnect的细节_PHP教程
-
深入探讨:PHP使用数据库永久连接方式操作MySQL的是与非
-
提高MySQL数据库查询效率的几个技巧[php程序员必看]
-
PHP程序中使用adodb连接不同数据库的代码实例_PHP
-
php连接不同数据库的几种方法
-
在windows上安装不同(两个)版本的Mysql数据库的教程详解