Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class dbconnect {
- protected $db_conn;
- public $db_user='xxxx';
- public $db_pass='xxxx';
- public $db_host='localhost';
- public $db_name='xxxx';
- function connect() {
- try{
- $this->db_conn=new PDO("mysql:host=$this->db_host;dbname=$this->db_name",$this->db_user,$this->db_pass);
- return $this->db_conn;
- }
- catch (Exception $e){
- return $e->getMessage();
- }
- }
- }
- include_once ( 'class.dbconn.php' );
- class Book{
- public $link;
- public function __construct(){
- $db_conn=new dbconnect();
- $this->link = $db_conn->connect();
- return $this->link;
- }
- }
- class new{
- include_once 'classes/class.book.php';
- $book = new Book();
- }
- public function disconnect() {
- $this->db_conn = null
- }
- public function __destruct() {
- $this->disconnect();
- }
- <?php
- class dbconnect {
- protected $db_conn;
- public $db_user='xxxx';
- public $db_pass='xxxx';
- public $db_host='localhost';
- public $db_name='xxxx';
- function connect() {
- try{
- $this->db_conn=new PDO("mysql:host=$this->db_host;dbname=$this->db_name",$this->db_user,$this->db_pass);
- return $this->db_conn;
- }
- catch (Exception $e){
- return $e->getMessage();
- }
- }
- function disconnect()
- {
- try
- {
- $this->db_conn=null;
- return $this->db_conn;
- }
- catch (Exception $e){
- return $e->getMessage();
- }
- }
- }
- }
- include_once ( 'class.dbconn.php' );
- class Book{
- public $link;
- public function __construct(){
- $db_conn=new dbconnect();
- $this->link = $db_conn->connect();
- return $this->link;
- }
- }
- class new{
- include_once 'classes/class.book.php';
- $book = new Book();
- $close = new dbconnect();
- // this will close connection
- $close->disconnect();
- }?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement