2013-05-17 34 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中。不知道問題在哪裏。

回答