gpt4 book ai didi

sql - 从不同的 Controller 插入 yii2

转载 作者:行者123 更新时间:2023-12-04 02:17:24 27 4
gpt4 key购买 nike

我想在表格中插入数据。

像这样尝试,但它不起作用。

$sql = $queryBuilder->insert(' HRMS_candidateEducation', [
'HRMS_candidateEducationCandidateID' => $candidateID,
'HRMS_candidateEducationDegree' => $data['Degree'.$i],
'HRMS_candidateEducationUniversity' => $data['University'.$i],
'HRMS_candidateEducationCollege' => $data['College'.$i],
'HRMS_candidateEducationYear' => $data['Specilization'.$i],
'HRMS_candidateEducationSpecilization' => $data['Specilization'.$i],
], $params);

哪里不对?

使用

use yii\db\QueryBuilder;
use app\models\CandidateEducation;

最佳答案

这个函数好像只创建SQL语句see doc

insert() Creates an INSERT command

为了执行命令,我认为你应该尝试这种方式

Yii::$app->db->createCommand()->
insert(' HRMS_candidateEducation', [
'HRMS_candidateEducationCandidateID' => $candidateID,
'HRMS_candidateEducationDegree' => $data['Degree'.$i],
'HRMS_candidateEducationUniversity' => $data['University'.$i],
'HRMS_candidateEducationCollege' => $data['College'.$i],
'HRMS_candidateEducationYear' => $data['Specilization'.$i],
'HRMS_candidateEducationSpecilization' => $data['Specilization'.$i],
], $params)->
execute();

关于sql - 从不同的 Controller 插入 yii2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33094095/

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