I have a separate config file to set db parameters.
<?php
define("DB_HOST", "localhost");
define("DB_USER", "root");
define("DB_PASS", "");
define("DB_NAME", "aa");
?>
And when user entered the user name and password, I open the database connection and validate the user in a another php file.
<?php
include("config.php");
include("database.php");
$dbo = database::getInstance();
$result=$dbo->connect(DB_HOST,DB_USER,DB_PASS,DB_NAME);
if($result){
$un = $_POST['username'];
$pw=$_POST['password'];
$dbo->validte_User_Login($un,$pw);
}
else
print "false";?>
Next I want to do some manipulations in database in another php file. Here how can I geet the already open database connection again without including the config file and calling connect method by passing parameters again?
My database connection function is as below.
function connect($host, $user, $pass, $dbName)
{
$this->host = $host;
$this->user = $user;
$this->pass = $pass;
$this->dbName = $dbName;
$db_handle = mysql_connect($this->host, $this->user,$this->pass);
$db_found = mysql_select_db($this->dbName, $db_handle);
if ($db_found) {
print "Database Found<br/>";
return true;
}
else
print "Database not Found<br/>";
return false;
}
$db_handleinside yourconnect()function. For other functions that require a database handle, you can call theconnect()function inside it.database::getInstance()?