Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Symfony-查询更新数据库_Php_Mysql_Sql_Function_Symfony - Fatal编程技术网

Php Symfony-查询更新数据库

Php Symfony-查询更新数据库,php,mysql,sql,function,symfony,Php,Mysql,Sql,Function,Symfony,我的Symofny中有一个函数,需要在单击时更新布尔字段。 我正在编写一个查询来执行它,但我认为我的语法不正确 return $this->getRepository() ->createQueryBuilder('aq') ->update('aq') ->set('aq.asked = 1') ->where('aq.asked = :asked') ->orderBy('aq

我的Symofny中有一个函数,需要在单击时更新布尔字段。 我正在编写一个查询来执行它,但我认为我的语法不正确

return $this->getRepository()
        ->createQueryBuilder('aq')
        ->update('aq')
        ->set('aq.asked = 1')
        ->where('aq.asked = :asked')
        ->orderBy('aq.id', 'asc')
        ->getQuery()
        ->getResult();

您必须添加setParameter,因为您添加了->where'aq.ask=:ask',但没有初始化:ask参数。 编辑:还需要将存储库名称添加到getRepository

return $this->getRepository('AppBundle:YourRepository')
        ->createQueryBuilder('aq')
        ->update('aq')
        ->set('aq.asked = 1')
        ->where('aq.asked = :asked')
        ->setParameter('asked', yourParameterValue);
        ->orderBy('aq.id', 'asc')
        ->getQuery()
        ->getResult();

您从哪个类调用它?为什么您认为这是一个语法问题?你的问题是什么?看见这个想法是你解释你正在尝试做什么,你尝试了什么,你得到了什么结果。