| | |
connect to two databases from the same script/page
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Apr 2009
Posts: 19
Reputation:
Solved Threads: 0
to connect/close connection my dbs i use the below include files
config.php
opendb.php
closedb.php
then on the a php page on top i have the below
i include config.php and opendb.php here
i include closedb.php here
how can i get the connection to $admindbconnection or $defaultdbconnection please?
config.php
PHP Syntax (Toggle Plain Text)
<?php // Admin Database Properties $admindbhost = 'localhost'; $admindbuser = 'user_default'; $admindbpass = '************'; $admindbname = 'db_admin'; // Default Database Properties $defaultdbhost = 'localhost'; $defaultdbuser = 'user_default'; $defaultdbpass = '************'; $defaultdbname = 'db_default'; ?>
opendb.php
PHP Syntax (Toggle Plain Text)
<?php // Admin Database Connection $admindbconnection = mysql_connect ($admindbhost, $admindbuser, $admindbpass) or die ('I cannot connect to the database because: ' . mysql_error()); mysql_select_db ($admindbname); // Default Database Connection $defaultdbconnection = mysql_connect ($defaultdbhost, $defaultdbuser, $defaultdbpass) or die ('I cannot connect to the database because: ' . mysql_error()); mysql_select_db ($defaultdbname); ?>
closedb.php
PHP Syntax (Toggle Plain Text)
<?php // Admin Database Close Connection mysql_close($admindbconnection); // Default Database Close Connection mysql_close($defaultdbconnection); ?>
then on the a php page on top i have the below
i include config.php and opendb.php here
PHP Syntax (Toggle Plain Text)
$query = "SELECT id, name, path FROM templates ORDER BY id"; $result = mysql_query($query) or die('Error : ' . mysql_error());
i include closedb.php here
how can i get the connection to $admindbconnection or $defaultdbconnection please?
•
•
Join Date: May 2008
Posts: 66
Reputation:
Solved Threads: 1
You can also use a join query to query two tables at the same time. It is better yo do it in one query as opposed to using multiple connections.
Kronik Media: Web design Company in London, UK.
Our Websites:
Estate Agent Website
Search engine marketing & eCommerce Resources for business
Our Websites:
Estate Agent Website
Search engine marketing & eCommerce Resources for business
php Syntax (Toggle Plain Text)
$result = mysql_query($query, $admindbconnection) or die('Error : ' . mysql_error());
http://php.net/manual/en/function.mysql-query.php
"If it is NOT source, it is NOT software."
-- NASA
-- NASA
![]() |
Similar Threads
- How to Connect MySQL from JSP Page (JSP)
- How to connect to two databases at the same time (MySQL)
- Connect different databases for different users (ASP.NET)
- cant get internet browser to connect to a link oe web page (Networking Hardware Configuration)
- mysql error only on web page (MySQL)
- transfer data from an asp .net page into a javasscript script (ASP.NET)
- "error has occured in script on this page" (Windows NT / 2000 / XP)
Other Threads in the PHP Forum
- Previous Thread: how to query between months ranges
- Next Thread: Linking two MySQL Databases ?
Views: 723 | Replies: 2
| Thread Tools | Search this Thread |
Tag cloud for PHP
.htaccess access ajax apache api array beginner binary broken cakephp checkbox class cms code cron curl database date directory display download dynamic echo email error errors file files folder form forms function functions google href htaccess html if...loop image include insert integration ip java javascript joomla jquery limit link login loop mail menu methods mlm mod_rewrite multiple mysql oop parse paypal pdf php problem query radio random recursion recursive regex remote script search select server sessions shot sms soap source space speed sql structure syntax system table tutorial update updates upload url validation validator variable vbulletin video web xml youtube





