我正在使用 CodeIgniter 进行开发,一段时间后我注意到所有查询都被执行了两次,如下面的 mySQL 日志所示:
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 查询运行时,所有信息都被插入两次,查看查询的顺序我可以得出结论,我没有调用模型两次,但是当我调用 "$this->db-> query($sql)" 这被发送到 mySQL 两次。也许我在 CodeIgniter 中有一些错误的数据库配置,你们中有人知道发生了什么吗?