gpt4 book ai didi

php - 类的单个初始化

转载 作者:行者123 更新时间:2023-12-04 05:42:31 24 4
gpt4 key购买 nike

我已将类的实例存储在类内的属性中,以进行无效的多次初始化(希望有意义)。

看起来像这样:

class baseClass
{
public $db;

public function __construct()
{
$this->db = new dbClass(); // this class is just a query class
}

}


class page extends baseClass {

public function __construct()
{
parent::__construct();
}

public function index()
{
// this works very fine and return result what i want //
$user = $this->db->query('blah blah');


// my problem is when i use the same property ($this->db) which
//contains the dbClass()

$mesg = $this->db->query('blah blah');

// the result of both query merge together
// i think i figured out whats the problem here but i dont know what to do
// i think i need to reset or the destroy the instance of $this->db
// and back it to null values


// or when i put print_r($this->db) after my first query (the $users )
// it display the previous property i set (ofcourse)
// what i want is.. every time i use the $this->db, i want
// it like the first time i use it, or fresh.
// is there any way ?
// thanks for the help experts ;)


}
}

最佳答案

问题出在您的 dbClass实现。似乎它无法将两个查询彼此分开。

你应该阅读dbClass的代码并找出如何分别运行两个查询;如果这是不可能的,您至少应该能够在开始另一个查询结果之前完成一个查询结果。

关于php - 类的单个初始化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11115315/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com