to connect/close connection my dbs i use the below include files

config.php

<?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
// 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
// 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

$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?

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.