request->all(); $odd=$data['form']['odd']; $stake=$da-6ren">
gpt4 book ai didi

php - 我如何在 symfony3 中使用 "INSERT SELECT"?

转载 作者:行者123 更新时间:2023-11-28 23:20:47 25 4
gpt4 key购买 nike

我想构建查询,将数据插入 mysql。

 $data=$request->request->all();
$odd=$data['form']['odd'];
$stake=$data['form']['stake'];
$win=$data['form']['win'];
$login_user=$data['form']['login_user'];

$separator = '\r\n';

$db = $this->getDoctrine()->getManager();
$query = "INSERT INTO zakladyuser (game, type, odd, stake, win, login_user, stat)
SELECT GROUP_CONCAT(game SEPARATOR :separator ), GROUP_CONCAT(type SEPARATOR :separator ), :odd, :stake, :win, :login_user, 0
FROM kupon k0";
$stmt = $db->prepare($query);
$params = array(
"separator"=>$separator,
"odd"=>$odd,
"stake"=>$stake,
"win"=>$win,
"login_user"=>$login_user
);
$stmt->execute($params);
$results = $stmt->fetchAll();

我可以纠正什么?因为我有这些错误:

Call to undefined method Doctrine\ORM\EntityManager::prepare()

Attempted to call an undefined method named "prepare" of class "Doctrine\ORM\EntityManager".

如果这条路错了,我怎样才能做得更好?

最佳答案

您需要在connection 对象中调用prepare():

$db = $this->getDoctrine()->getManager();
..
$stmt = $db->getConnection()->prepare($query);

关于php - 我如何在 symfony3 中使用 "INSERT SELECT"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41686162/

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