OOP database connect/disconnect class

前端 未结 6 1439
无人及你
无人及你 2020-12-09 00:05

I have just started learning the concept of Object oriented programming and have put together a class for connecting to a database, selecting database and closing the databa

6条回答
  •  死守一世寂寞
    2020-12-09 00:51

    host         =   'localhost';
            $this->username     =   'root';
            $this->password     =   '';
            $this->database     =   'workclass';
    
            $this->link = mysqli_connect($this->host,$this->username,$this->password);
    
            $this->status = mysqli_select_db($this->link,$this->database);
    
            if (!$this->status) {
                return $this->status="Failed to Connected with Database";
            }else{
                return $this->status="Database is connected";
            }
        }
    }
    
    $object = new Database();
    
    echo $object->status;
    
    ?>
    

提交回复
热议问题