[英]MySQL Error No: 1064 when INSERTING to Database
Below is my table which is similar to another existing table. 下面是我的表,它与另一个现有表相似。 But I get one error when executing the query.
但是执行查询时出现一个错误。
//
public function addFirstChild() {
$this->db->query("INSERT INTO " . $this->db->table("genealogy") . "
WHERE parent_id = '" . (int)$this->getSponsorID() . "'
SET first_child = '" . (int)$this->getId()."',
genealogy_id = '" . (int)$this->getId() ."'");
}
When executed I get the below Error: 执行时,出现以下错误:
SQL Error: You have an error in your SQL syntax;
SQL错误:您的SQL语法有错误; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE parent_id = '1' SET first_child = '2', ' at line 2 Error No: 1064 SQL: INSERT INTO ci_genealogy WHERE parent_id = '1' SET first_child = '2', genealogy_id = '2' in C:\\wamp64\\www\\s1nb2\\core\\database\\amysqli.php on line 108
检查与您的MySQL服务器版本相对应的手册,以在第2行的'WHERE parent_id ='1'SET first_child ='2','附近使用正确的语法错误编号:1064 SQL:INSERT INTO ci_genealogy WHERE parent_id ='1'在第108行的C:\\ wamp64 \\ www \\ s1nb2 \\ core \\ database \\ amysqli.php中设置first_child ='2',genealogy_id ='2'
There's no other way that I can think of to pull of this function and I have searched online and read multiple posts with the same error but still no solution. 我没有其他办法可以想到要使用此功能,并且我已经在线搜索并阅读了多个具有相同错误但仍没有解决方案的帖子。 Please help.
请帮忙。 I spent over 4 hours trying to get this right.
我花了4个多小时来尝试解决这个问题。
Since you're using a WHERE
it appears that you want to change an existing record. 由于您使用的是
WHERE
因此似乎要更改现有记录。 You want an UPDATE
, not an INSERT
您需要
UPDATE
而不是INSERT
"UPDATE " . $this->db->table("genealogy") . "
SET first_child = '" . (int)$this->getId()."', genealogy_id = '" . (int)$this->getId() ."'
WHERE parent_id = '" . (int)$this->getSponsorID() . "'"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.