首页 > 解决方案 > 如何在原始查询 Symfony 中添加 union all?

问题描述

我需要UNION ALL在我的查询中使用。我已将所有 where 条件存储在一个循环中。

    $lastIndex = count($executionArray) - 1;
    $selectQuery = "";
    foreach ($executionArray as $key => $wheres) {
        $selectQuery .= "SELECT {$selectFields} FROM {$tableName} WHERE ";
        $selectQuery .= $wheres;
        if ($key !== $lastIndex) {
            $selectQuery .= " UNION ALL ";
        }
    }

    $selectStmt = $this->dbConnection->prepare($selectQuery);
    $selectStmt->execute($executionArray);
    $return = $selectStmt->fetchAll();

我收到数组到字符串的转换错误。我不知道该放在哪里prepare & execute statement

任何人都可以帮我解决这个问题。

谢谢你。

标签: phpsymfony4

解决方案


推荐阅读