我有一个非常好的查询,当我在我的数据库中使用它而不是在CodeIgniter中时它会起作用。查询看起来像这样
SET @student_id = 1;
INSERT IGNORE INTO tbl_beschikbare_data (datum_tijd) VALUES ('22/22/2222');
SET @bd_id = LAST_INSERT_ID();
INSERT INTO tbl_student_beschikbare_data (student_id,bd_id) VALUES(@student_id, @bd_id);
这就是我在CodeIgniter中所拥有的:
public function save($t){
$this->db->query("SET @student_id = 1;INSERT IGNORE INTO tbl_beschikbare_data (datum_tijd) VALUES ('".$t."');SET @bd_id = LAST_INSERT_ID();INSERT INTO tbl_student_beschikbare_data (student_id,bd_id) VALUES(@student_id, @bd_id);
"); }
答案 0 :(得分:1)
好好想通了..效果很好
public function save($datum_tijd) {
$this->db->query("SET @student_id = 1;");
$this->db->query("INSERT IGNORE INTO tbl_beschikbare_data (datum_tijd) VALUES ('".$datum_tijd."');");
$this->db->query("SET @bd_id = LAST_INSERT_ID();");
$this->db->query("INSERT INTO tbl_student_beschikbare_data (student_id,bd_id) VALUES(@student_id, @bd_id);");
}