gpt4 book ai didi

php - MySQL 错误编号 : 1064 when INSERTING to Database

转载 作者:行者123 更新时间:2023-11-29 01:51:27 29 4
gpt4 key购买 nike

下面是我的表格,它与另一个现有表格相似。但是我在执行查询时遇到一个错误。

//
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() ."'");

}

执行时出现以下错误:

SQL Error: 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 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

我想不出其他方法来实现这个功能,我在网上搜索并阅读了多篇出现相同错误的帖子,但仍然没有解决方案。请帮忙。我花了 4 个多小时试图解决这个问题。

最佳答案

由于您正在使用 WHERE,因此您似乎想要更改现有记录。您需要 UPDATE,而不是 INSERT

"UPDATE " . $this->db->table("genealogy") . "
SET first_child = '" . (int)$this->getId()."', genealogy_id = '" . (int)$this->getId() ."'
WHERE parent_id = '" . (int)$this->getSponsorID() . "'"

关于php - MySQL 错误编号 : 1064 when INSERTING to Database,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41395806/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com