2017-07-16 37 views
-1

我有两个PHP类(DBOperations.php和functions.php)。现在我想从functions.php类的DBOperations.php类中设置一个值。PHP设置值的类

class DBOperations{ 

    private $host = 'localhost'; 
    private $user = 'u'; 
    public $database; 
    private $pass = 'p'; 
    private $conn; 

public function __construct() { 



    $this -> conn = new PDO("mysql:host=".$this -> host.";dbname=".$this -> database, $this -> user, $this -> pass); 

    } 
public function doMagic() { 
//running mysql queries here 
} 

和functions.php中:

require_once 'DBOperations.php'; 

class Functions{ 

private $db; 

public function __construct() { 

     $this -> db = new DBOperations(); 
} 
public function doThings($variable) { 

    $db = $this -> db; 
    //here I want to set the value $database from the DBOperations class to //$variable 

有人可以帮助NME了呢?

问候弗朗西斯

+1

'$此函数属性设置中的functions.php类的函数定义它 - >数据库 - > database' –

回答

0

您可以通过像

public function doThings($variable) { 

    $db = $this -> db; 
    $this->db->database = 'dbname'; 
    // same for all variables if they are public 
}