2013-05-17 31 views
0

我想运行下面的代码,只有当我在where子句中使用not条件时才会出错。我知道我应该使用cake的save方法,但由于某种原因,我必须使用$ this-> model-> query。

$this->Model->query("insert into students values ($department_id,$class_id) where depid <> $department_id and classid <> $class_id"); 

我收到错误如下:如果我直接用

SQL Error: 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'where tagid <> 1 and contactid <> 32' at line 1 [CORE\cake\libs\model\datasources\dbo_source.php, line 681] 


Query: insert into students values(3,2) where depid <> 3 and classid <> 2 

我试图把DEPID = 3,而不是DEPID = 3,但没有什么工作,通过CakePHP的,但是,<>工作正常在MySql中。不知道问题在哪里。

回答