对不起我的英语。我执行一个唯一的查询插入,但在数据库中创建的许多记录相等。我有一个带有模式单例和注册表的 php cms mvc。当我调用控制器时,加载了核心的所有模型,包括管理数据库的模型。
我写了一段代码:
class DB extends global_core
{
private $PDO;
private $result;
public function __construct()
{
parent::__construct();
}
public function query($query)
{
$this->result = $this->PDO->prepare($query);
$this->result->execute();
return $this->result;
}
}
在另一个模型中运行此方法:
class Stats extends global_core
{
private $stored_agent = false;
public function __construct()
{
parent::__construct();
if (!$this->stored_agent)
$this->saveAgent();
}
public function saveAgent()
{
if ($this->stored_agent) return;
$this->DB->query('INSERT ...');
echo 'ok';
$this->stored_agent = true;
}
}
现在在我的数据库中创建了"n"相等的记录,但在视频中正确打印的只有"ok"而不是"okokokok"。
为什么?
但是,如果我从当前控制器调用该方法,我正确地只会得到一条新记录。
class page extends controller
{
public function __construct()
{
parent::__construct();
$this->loadInfo();
}
protected function loadInfo()
{
$this->Stats->saveAgent();
}
}
所以它工作正常...
问题出在哪里?
已解决是配置错误的 URL 重写问题。调用服务器上不存在的图像,被收取再次实例化核心的网站的错误页面......
<img src="file not present" >