簡體   English   中英

PDO-PHP查詢再次執行而無需調用

[英]PDO - PHP query executed again without call

對不起我的英語不好。 我執行唯一查詢INSERT,但是在數據庫中創建了許多相等的記錄。 我有一個帶模式單例和注冊表的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”而不是“ okokokokokokokok”。

為什么?

但是,如果我從當前控制器調用該方法,那么我只會得到一條新記錄。

class page extends controller
{
    public function __construct()
    {
        parent::__construct();

        $this->loadInfo();
    }

    protected function loadInfo()
    {
        $this->Stats->saveAgent();
    }
}

所以它可以正常工作...

問題出在哪兒?

已解決是URL配置重寫錯誤的問題。 調用服務器上不存在的映像,已被收費,該站點的錯誤頁面再次實例化了核心...

<img src="file not present" >

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM