SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Threaded View

  1. #1
    SitePoint Enthusiast
    Join Date
    Feb 2012
    Posts
    49
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Question connection class problem

    dear all here my connection class
    PHP Code:
    <?php
    class Conn_DB {
        private static 
    $_cbInstance NULL;
        private function 
    __construct(){}
        public function 
    __clone(){
            
    trigger_error("Error",E_USER_ERROR);
        }
        public function 
    __wakeup(){
            
    trigger_error("Error",E_USER_ERROR);
        }
        public static function 
    getCBConnect(){
            if(!isset(
    self::$_cbInstance)){
                try{
                    
    self::$_cbInstance = new PDO("mysql:host=localhost;dbname=testingDB;charset=UTF-8","username","password");
                }
                catch (
    PDOException $e){
                    die(
    $e->getMessage());
                }
                return 
    self::$_cbInstance;
            }
        }
        public function 
    __destruct() {
        }
    }
    nothing wrong but when i used my select class
    PHP Code:
    <?php
    class SelectDatabase{
        function 
    select($connect,$field,$table){
            
    $query "SELECT ".$field." FROM ".$table;
            
    $stmt $connect->prepare($query);
            
    $stmt->execute();
            return 
    $stmt;
        }
        function 
    selectWhere($connect,$field,$table,$whereclause){
            
    $query "SELECT ".$field." FROM ".$table." ".$whereclause;
            
    $stmt $connect->prepare($query);
            
    $stmt->execute();
            return 
    $stmt;
        }
        public function 
    __destruct(){}
    }
    ?>
    here my function
    PHP Code:
    <?php
        
    function fnc_select($table)
        {
            
    $conn Conn_DB::getCBConnect();
            
    $sel = new SelectDatabase();
            
    $statement $sel->select($conn," * " ,$table);
            return 
    $statement;
        }    
    ?>
    it work actually but the problem is my public function __destruct(){} when i want to use same select class for another in the same page it fatal error because i my connection class was __destruct so any way use 1 connection and 1 select class for whole project?
    Last edited by cpradio; Jan 23, 2013 at 07:06. Reason: Removed username and password


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •