0

私は CodeIgniter で開発していますが、しばらくして、以下の mySQL ログが示すように、すべてのクエリが 2 回実行されていることに気付きました。

           55 Query SELECT user_display FROM user WHERE user_id=1
       55 Query SELECT user_display FROM user WHERE user_id=1
       55 Query SELECT TIMEDIFF(NOW(),contest_create) FROM contest WHERE contest_id=95
       55 Query SELECT TIMEDIFF(NOW(),contest_create) FROM contest WHERE contest_id=95
       55 Query SELECT TIMEDIFF(ADDDATE(contest_create, INTERVAL contest_duration DAY),NOW()) FROM contest WHERE contest_id=95
       55 Query SELECT TIMEDIFF(ADDDATE(contest_create, INTERVAL contest_duration DAY),NOW()) FROM contest WHERE contest_id=95
       55 Query SELECT add_addon_id FROM addon_contest WHERE add_contest_id=95
       55 Query SELECT add_addon_id FROM addon_contest WHERE add_contest_id=95
       55 Query SELECT addon_name FROM addon WHERE addon_id='1' OR addon_id='4'
       55 Query SELECT addon_name FROM addon WHERE addon_id='1' OR addon_id='4'
       55 Query SELECT required_skill_id FROM skill_contest WHERE required_contest_id=95
       55 Query SELECT required_skill_id FROM skill_contest WHERE required_contest_id=95
       55 Query SELECT skill_name FROM skill WHERE skill_id='2' OR skill_id='4' OR skill_id='13'
       55 Query SELECT skill_name FROM skill WHERE skill_id='2' OR skill_id='4' OR skill_id='13'
       55 Query SELECT user_display FROM user WHERE user_id=2
       55 Query SELECT user_display FROM user WHERE user_id=2
       55 Query SELECT TIMEDIFF(NOW(),contest_create) FROM contest WHERE contest_id=9
       55 Query SELECT TIMEDIFF(NOW(),contest_create) FROM contest WHERE contest_id=9
       55 Query SELECT TIMEDIFF(ADDDATE(contest_create, INTERVAL contest_duration DAY),NOW()) FROM contest WHERE contest_id=9
       55 Query SELECT TIMEDIFF(ADDDATE(contest_create, INTERVAL contest_duration DAY),NOW()) FROM contest WHERE contest_id=9
       55 Query SELECT add_addon_id FROM addon_contest WHERE add_contest_id=9
       55 Query SELECT add_addon_id FROM addon_contest WHERE add_contest_id=9
       55 Query SELECT addon_name FROM addon WHERE addon_id='1'
       55 Query SELECT addon_name FROM addon WHERE addon_id='1'
       55 Query SELECT required_skill_id FROM skill_contest WHERE required_contest_id=9
       55 Query SELECT required_skill_id FROM skill_contest WHERE required_contest_id=9
       55 Query SELECT skill_name FROM skill WHERE skill_id='1' OR skill_id='4'
       55 Query SELECT skill_name FROM skill WHERE skill_id='1' OR skill_id='4'
       55 Query SELECT user_display FROM user WHERE user_id=2
       55 Query SELECT user_display FROM user WHERE user_id=2
       55 Query SELECT TIMEDIFF(NOW(),contest_create) FROM contest WHERE contest_id=16
       55 Query SELECT TIMEDIFF(NOW(),contest_create) FROM contest WHERE contest_id=16
       55 Query SELECT TIMEDIFF(ADDDATE(contest_create, INTERVAL contest_duration DAY),NOW()) FROM contest WHERE contest_id=16
       55 Query SELECT TIMEDIFF(ADDDATE(contest_create, INTERVAL contest_duration DAY),NOW()) FROM contest WHERE contest_id=16
       55 Query SELECT add_addon_id FROM addon_contest WHERE add_contest_id=16
       55 Query SELECT add_addon_id FROM addon_contest WHERE add_contest_id=16
       55 Query SELECT addon_name FROM addon WHERE addon_id='2' OR addon_id='4'
       55 Query SELECT addon_name FROM addon WHERE addon_id='2' OR addon_id='4'
       55 Query SELECT required_skill_id FROM skill_contest WHERE required_contest_id=16
       55 Query SELECT required_skill_id FROM skill_contest WHERE required_contest_id=16
       55 Query SELECT skill_name FROM skill WHERE skill_id='16'
       55 Query SELECT skill_name FROM skill WHERE skill_id='16'
       55 Query SELECT user_display FROM user WHERE user_id=1
       55 Query SELECT user_display FROM user WHERE user_id=1
       55 Query SELECT TIMEDIFF(NOW(),contest_create) FROM contest WHERE contest_id=68
       55 Query SELECT TIMEDIFF(NOW(),contest_create) FROM contest WHERE contest_id=68
       55 Query SELECT TIMEDIFF(ADDDATE(contest_create, INTERVAL contest_duration DAY),NOW()) FROM contest WHERE contest_id=68
       55 Query SELECT TIMEDIFF(ADDDATE(contest_create, INTERVAL contest_duration DAY),NOW()) FROM contest WHERE contest_id=68
       55 Query SELECT add_addon_id FROM addon_contest WHERE add_contest_id=68
       55 Query SELECT add_addon_id FROM addon_contest WHERE add_contest_id=68
       55 Query SELECT addon_name FROM addon WHERE addon_id='7'
       55 Query SELECT addon_name FROM addon WHERE addon_id='7'
       55 Query SELECT required_skill_id FROM skill_contest WHERE required_contest_id=68
       55 Query SELECT required_skill_id FROM skill_contest WHERE required_contest_id=68
       55 Query SELECT skill_name FROM skill WHERE skill_id='1' OR skill_id='3'
       55 Query SELECT skill_name FROM skill WHERE skill_id='1' OR skill_id='3'
       55 Query SELECT user_display FROM user WHERE user_id=1
       55 Query SELECT user_display FROM user WHERE user_id=1
       55 Query SELECT TIMEDIFF(NOW(),contest_create) FROM contest WHERE contest_id=79
       55 Query SELECT TIMEDIFF(NOW(),contest_create) FROM contest WHERE contest_id=79
       55 Query SELECT TIMEDIFF(ADDDATE(contest_create, INTERVAL contest_duration DAY),NOW()) FROM contest WHERE contest_id=79
       55 Query SELECT TIMEDIFF(ADDDATE(contest_create, INTERVAL contest_duration DAY),NOW()) FROM contest WHERE contest_id=79
       55 Query SELECT add_addon_id FROM addon_contest WHERE add_contest_id=79
       55 Query SELECT add_addon_id FROM addon_contest WHERE add_contest_id=79
       55 Query SELECT addon_name FROM addon WHERE addon_id='4'
       55 Query SELECT addon_name FROM addon WHERE addon_id='4'
       55 Query SELECT required_skill_id FROM skill_contest WHERE required_contest_id=79
       55 Query SELECT required_skill_id FROM skill_contest WHERE required_contest_id=79
       55 Query SELECT skill_name FROM skill WHERE skill_id='2' OR skill_id='4' OR skill_id='6'
       55 Query SELECT skill_name FROM skill WHERE skill_id='2' OR skill_id='4' OR skill_id='6'
       55 Query SELECT user_display FROM user WHERE user_id=1
       55 Query SELECT user_display FROM user WHERE user_id=1
       55 Query SELECT TIMEDIFF(NOW(),contest_create) FROM contest WHERE contest_id=86
       55 Query SELECT TIMEDIFF(NOW(),contest_create) FROM contest WHERE contest_id=86
       55 Query SELECT TIMEDIFF(ADDDATE(contest_create, INTERVAL contest_duration DAY),NOW()) FROM contest WHERE contest_id=86
       55 Query SELECT TIMEDIFF(ADDDATE(contest_create, INTERVAL contest_duration DAY),NOW()) FROM contest WHERE contest_id=86
       55 Query SELECT add_addon_id FROM addon_contest WHERE add_contest_id=86
       55 Query SELECT add_addon_id FROM addon_contest WHERE add_contest_id=86
       55 Query SELECT addon_name FROM addon WHERE addon_id='2' OR addon_id='3'
       55 Query SELECT addon_name FROM addon WHERE addon_id='2' OR addon_id='3'
       55 Query SELECT required_skill_id FROM skill_contest WHERE required_contest_id=86
       55 Query SELECT required_skill_id FROM skill_contest WHERE required_contest_id=86
       55 Query SELECT skill_name FROM skill WHERE skill_id='8' OR skill_id='13'
       55 Query SELECT skill_name FROM skill WHERE skill_id='8' OR skill_id='13'
       55 Query SELECT user_display FROM user WHERE user_id=1
       55 Query SELECT user_display FROM user WHERE user_id=1
       55 Query SELECT TIMEDIFF(NOW(),contest_create) FROM contest WHERE contest_id=92
       55 Query SELECT TIMEDIFF(NOW(),contest_create) FROM contest WHERE contest_id=92
       55 Query SELECT TIMEDIFF(ADDDATE(contest_create, INTERVAL contest_duration DAY),NOW()) FROM contest WHERE contest_id=92
       55 Query SELECT TIMEDIFF(ADDDATE(contest_create, INTERVAL contest_duration DAY),NOW()) FROM contest WHERE contest_id=92
       55 Query SELECT add_addon_id FROM addon_contest WHERE add_contest_id=92
       55 Query SELECT add_addon_id FROM addon_contest WHERE add_contest_id=92
       55 Query SELECT addon_name FROM addon WHERE addon_id='3' OR addon_id='4' OR addon_id='5' OR addon_id='8'
       55 Query SELECT addon_name FROM addon WHERE addon_id='3' OR addon_id='4' OR addon_id='5' OR addon_id='8'
       55 Query SELECT required_skill_id FROM skill_contest WHERE required_contest_id=92
       55 Query SELECT required_skill_id FROM skill_contest WHERE required_contest_id=92
       55 Query SELECT skill_name FROM skill WHERE skill_id='3' OR skill_id='6' OR skill_id='19'
       55 Query SELECT skill_name FROM skill WHERE skill_id='3' OR skill_id='6' OR skill_id='19'
       55 Query SELECT user_display FROM user WHERE user_id=2
       55 Query SELECT user_display FROM user WHERE user_id=2
       55 Query SELECT TIMEDIFF(NOW(),contest_create) FROM contest WHERE contest_id=12
       55 Query SELECT TIMEDIFF(NOW(),contest_create) FROM contest WHERE contest_id=12
       55 Query SELECT TIMEDIFF(ADDDATE(contest_create, INTERVAL contest_duration DAY),NOW()) FROM contest WHERE contest_id=12
       55 Query SELECT TIMEDIFF(ADDDATE(contest_create, INTERVAL contest_duration DAY),NOW()) FROM contest WHERE contest_id=12
       55 Query SELECT add_addon_id FROM addon_contest WHERE add_contest_id=12
       55 Query SELECT add_addon_id FROM addon_contest WHERE add_contest_id=12
       55 Query SELECT addon_name FROM addon WHERE addon_id='3' OR addon_id='4' OR addon_id='8'
       55 Query SELECT addon_name FROM addon WHERE addon_id='3' OR addon_id='4' OR addon_id='8'
       55 Query SELECT required_skill_id FROM skill_contest WHERE required_contest_id=12
       55 Query SELECT required_skill_id FROM skill_contest WHERE required_contest_id=12
       55 Query SELECT skill_name FROM skill WHERE skill_id='11'
       55 Query SELECT skill_name FROM skill WHERE skill_id='11'
       55 Query SELECT user_display FROM user WHERE user_id=1
       55 Query SELECT user_display FROM user WHERE user_id=1
       55 Query SELECT TIMEDIFF(NOW(),contest_create) FROM contest WHERE contest_id=34
       55 Query SELECT TIMEDIFF(NOW(),contest_create) FROM contest WHERE contest_id=34
       55 Query SELECT TIMEDIFF(ADDDATE(contest_create, INTERVAL contest_duration DAY),NOW()) FROM contest WHERE contest_id=34
       55 Query SELECT TIMEDIFF(ADDDATE(contest_create, INTERVAL contest_duration DAY),NOW()) FROM contest WHERE contest_id=34
       55 Query SELECT add_addon_id FROM addon_contest WHERE add_contest_id=34
       55 Query SELECT add_addon_id FROM addon_contest WHERE add_contest_id=34
       55 Query SELECT add_addon_id FROM addon_contest WHERE add_contest_id=34
       55 Query SELECT required_skill_id FROM skill_contest WHERE required_contest_id=34
       55 Query SELECT required_skill_id FROM skill_contest WHERE required_contest_id=34
       55 Query SELECT skill_name FROM skill WHERE skill_id='3'
       55 Query SELECT skill_name FROM skill WHERE skill_id='3'
       55 Query SELECT user_display FROM user WHERE user_id=1
       55 Query SELECT user_display FROM user WHERE user_id=1
       55 Query SELECT TIMEDIFF(NOW(),contest_create) FROM contest WHERE contest_id=74
       55 Query SELECT TIMEDIFF(NOW(),contest_create) FROM contest WHERE contest_id=74
       55 Query SELECT TIMEDIFF(ADDDATE(contest_create, INTERVAL contest_duration DAY),NOW()) FROM contest WHERE contest_id=74
       55 Query SELECT TIMEDIFF(ADDDATE(contest_create, INTERVAL contest_duration DAY),NOW()) FROM contest WHERE contest_id=74
       55 Query SELECT add_addon_id FROM addon_contest WHERE add_contest_id=74
       55 Query SELECT add_addon_id FROM addon_contest WHERE add_contest_id=74
       55 Query SELECT addon_name FROM addon WHERE addon_id='1'
       55 Query SELECT addon_name FROM addon WHERE addon_id='1'
       55 Query SELECT required_skill_id FROM skill_contest WHERE required_contest_id=74
       55 Query SELECT required_skill_id FROM skill_contest WHERE required_contest_id=74
       55 Query SELECT skill_name FROM skill WHERE skill_id='2'
       55 Query SELECT skill_name FROM skill WHERE skill_id='2'
       55 Query SELECT skill_name FROM skill WHERE skill_status=2
       55 Query SELECT skill_name FROM skill WHERE skill_status=2
       55 Quit  

問題は、いくつかの INSERT クエリが実行されると、すべての情報が 2 回挿入され、クエリの順序を見ると、モデルを 2 回呼び出していないと結論付けることができますが、"$this->db-> を呼び出すとquery($sql)" これは mySQL に 2 回送信されています。CodeIgniter のデータベース設定が間違っているのかもしれません。

4

1 に答える 1

0

さて、php のバージョンが原因で、codeigniter システム内の CI_DB_pdo_driver の _execute() 関数が正しく動作していないことがわかりました。とにかく、CodeIgniter のコードを次のように変更しました。

    function _execute($sql)
{
    $sql = $this->_prep_query($sql);
    $result_id = $this->conn_id->prepare($sql);
    $result_id->execute();

    if (is_object($result_id))
    {
        if (is_numeric(stripos($sql, 'SELECT')))
        {
            $this->affect_rows = count($result_id->fetchAll());
            $result_id->execute();
        }
        else
        {
            $this->affect_rows = $result_id->rowCount();
        }
    }
    else
    {
        $this->affect_rows = 0;
    }

    return $result_id;
}

に:

    function _execute($sql)
{
    $sql = $this->_prep_query($sql);
    $result_id = $this->conn_id->prepare($sql);
    $result_id->execute();

    if (is_object($result_id))
    {
        if (preg_match('/^\s*"?(SELECT)\s+/i', $sql))
        {
            $this->affect_rows = count($result_id->fetchAll());
            $result_id->execute();
        }
        else
        {
            $this->affect_rows = $result_id->rowCount();
        }
    }
    else
    {
        $this->affect_rows = 0;
    }

    return $result_id;
}

$sql に「SELECT」が含まれているかどうかをテストする部分が機能していなかったため、INSERT を実行しようとすると、「$result_id->execute()」が 2 回呼び出されていました。

于 2013-11-04T15:21:03.360 に答える