gpt4 book ai didi

mysql - Symfony2 : How to flush multiple rows in database in one query

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

我有 3 行要插入同一个表中,该表要从一个查询中一次性插入。这是我试过的:

Controller 函数:

public function addAction(Request $request)
{
$entity = new GlobalSetting();

$minPLabel = $_POST['minPlayer'];
$minPValue = $_POST['minPlayerValue'];
$maxPLabel = $_POST['maxPlayer'];
$maxPValue = $_POST['maxPlayerValue'];
$overLabel = $_POST['overs'];
$overValue = $_POST['oversValue'];

if ($request->getMethod() == 'POST')
{
// echo "<pre>"; print_r($_POST); exit;
$entity->setKeyName($minPLabel);
$entity->setValue($minPValue);

$entity->setKeyName($maxPLabel);
$entity->setValue($maxPValue);

$entity->setKeyName($overLabel);
$entity->setValue($overValue);

$em = $this->getDoctrine()->getManager();
$em->persist($entity);
$em->flush();

return $this->redirect($this->generateUrl('global'));
}

return $this->redirect($this->generateUrl('global'));
}

这只是插入最后一条记录,我知道会有一些循环出现但不知道如何执行它。请帮助我被困住了。谢谢

最佳答案

我建议你像下面这样使用

    $minEntity = new GlobalSetting();
$minEntity->setKeyName($minPLabel);
$minEntity->setValue($minPValue);

$maxEntity = new GlobalSetting();
$maxEntity->setKeyName($maxPLabel);
$maxEntity->setValue($maxPValue);

$overEntity = new GlobalSetting();
$overEntity->setKeyName($overLabel);
$overEntity->setValue($overValue);

$em = $this->getDoctrine()->getManager();
$em->persist($minEntity);
$em->persist($maxEntity);
$em->persist($overEntity);
$em->flush();

关于mysql - Symfony2 : How to flush multiple rows in database in one query,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31583215/

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