我想构建查询,将数据插入 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/