【发布时间】:2020-09-29 15:30:29
【问题描述】:
我有这个问题:
SQLSTATE[23000]:完整性约束违规:1452 无法添加或更新子行:外键约束失败(tutoblog.post_category,CONSTRAINT fk_category FOREIGN KEY(category_id)参考category (id) 更新级联删除级联)
【问题讨论】:
-
公共函数 attachCategories(int $id,array $categories){ $this->pdo->exec('DELETE FROM post_category WHERE post_id = ' . $id); $query= $this->pdo->prepare('INSERT INTO post_category SET post_id = ?,category_id = ?'); foreach ($categories as $category){ $query->execute([$id, $category]); } }
-
公共函数选择(字符串 $key,字符串 $label,数组 $options = []):字符串 { $optionsHTML = []; $value = $this->getValue($key); foreach ($options as $K => $v) { $selected = in_array($key,$value) ? “选定”:“”; $optionsHTML[] = "$v" ; } $optionsHTML = implode('', $optionsHTML);返回 {$this->getErrorFeedback($key)}HTML;
标签: php