How to match parameters from getParameters with getSQL? #10370
Unanswered
LorisZ
asked this question in
Support Questions
Replies: 1 comment 1 reply
-
I was trying to do something similar and figured it out: you have to manually parse the query with a $parser = new Parser($query);
$parserResult = $parser->parse();
$params = [];
$types = [];
foreach ($query->getParameters() as $parameter) {
$positions = $parserResult->getSqlParameterPositions($parameter->getName());
foreach ($positions as $position) {
$params[$position] = $parameter->getValue();
$types[$position] = $parameter->getType();
}
}
$result = $query->getEntityManager()->getConnection()->executeQuery($query->getSQL(), $params, $types);
$rows = $result->fetchAllAssociative(); |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
When I build a query from QueryBuilder with DQL and want to use the resulting Query somewhere else, I try to do
Which gives me something like this:
$sql:
$parameters:
How am I supposed to match the
?
in the query with the named parameters? I thought maybe it's in the same order, but since even the numbers don't necessarily match (named parameters can be used several times as in the example above), it's just not possible. I have not found another public method or different parameters that would help me here. Also found some similar posts on stackoverflow, but short from guessing or modifying the doctrine files I did not really find any satisfying answers...I was trying this on version 2.5.14, but when I took a quick look in the source code it did not seem any different even on 3.0.
Beta Was this translation helpful? Give feedback.
All reactions