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 中使用 <> 工作正常。不知道问题出在哪里。

4

1 回答 1

0

INSERT 表达式没有 WHERE CLAUSE。阅读文档

于 2013-05-17T06:18:11.660 回答