0

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?

3
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by pritaeas
0

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.

This article has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.