I can not get ur question. it not clear what is the actual problem is.
I think you have a seperate file (.inc) to include the database connection and query.
i have define a class to connect the database and query. just include this file and using it.
$mydb = new db;
$mydb ->connect("databasename")
$sql = "select field1, field2 from table";
$row =$mydb->selectqry($sql);
I think this will solve your problem.
class db {
var $result;
var $dbname;
var $row;
var $no_of_rows;
var $effrow;
var $link;
//Data base Connection Function
// in your Program You should use like
// $mydb = new db; this create a new object.
//$mydb->connect($dbname); you have to
//pass your database name to connect that.
function connect($dbname)
{
$this->dbname = $dbname;
$this->link = mysql_connect ("ipaddress","user","password");
mysql_select_db($dbname);
}
//For Select Query, where you have to pass sql query from your program.
function selectqry($sql)
{
$row=mysql_db_query($this->dbname,$sql);
return $row; // row will return the record set.
}
// This function will load all the record into the array.
function fetch ($row)
{
$dataarray= mysql_fetch_row($row);
return $dataarray; // dataarray is the array with the all the record.
}
// This function to find out total number of record in your record set and
// will return the value into the Noofrows varaible.
function numrows($row)
{
$num_rows= mysql_num_rows($row);
return $num_rows;
}
// this function to insert, update, Delete the record from the table.
// effrow varible return to the value of effected rows of table.
function query ($sql)
{
$effrow=mysql_db_query($this->dbname,$sql);
return $effrow;
}
function close ()
{
mysql_close($this->link);
}
}
?>