epifanio67
asked on
PHP5: when do I close my database object connection?
Hello Experts,
In the sample database code below, when do I close the database obj connection?
I use the object to query the db throughout the session....
Regards,
In the sample database code below, when do I close the database obj connection?
I use the object to query the db throughout the session....
//***** index.php
require_once 'Database.php';
$db = new Database();
$db->getInstance();
$db->testQuery();
$email = $db->testQuery();
//***** Database.php
class Database extends mysqli_stmt {
//set db access data
private $server = "localhost";
private $user = "test";
private $pass = "test";
private $db = "test";
private $instance;
function getInstance(){
$db = new mysqli ( $this->server, $this->db, $this->pass, $this->user );
if ($db->connect_error) {
die('Connect Error (' . $instance->connect_errno . ') ');
} else {
$this->instance = $db;
}
return $this->instance;
}
function testQuery( $name ){
$stmt = $this->instance->stmt_init();
$query = "SELECT `email` FROM customers WHERE Name=?";
if ($stmt->prepare($query)) {
$stmt->bind_param("s", $name);
$stmt->execute();
$stmt->bind_result( $email );
$stmt->fetch();
$stmt->close();
}
return $email;
}
function dbClose(){
$this->instance->close();
}
}//END OF CLASS...
Regards,
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Regards,