Issue
I am trying to debug a SQL statement I have not written myself:
$stmt = $dbh->prepare("
SELECT
Customer.Primary_Email AS EMAIL,
...
FROM Order_SG
INNER JOIN Customer USING (Customer__)
INNER JOIN Order_SG_Detail USING (Order_SG__)
INNER JOIN Product_Ref USING (Product_Ref__)
INNER JOIN Reduction USING (Reduction__)
WHERE Order_SG.Server__ IN (:servers)
...
AND `DATE` BETWEEN :startDate AND :endDate
LIMIT :limit
OFFSET :offset");
$stmt->bindValue(':servers', implode(',', $servers));
$stmt->bindValue(':startDate', $startDate);
$stmt->bindValue(':endDate', $endDate);
$stmt->bindValue(':limit', $limit, \PDO::PARAM_INT);
$stmt->bindValue(':offset', $offset, \PDO::PARAM_INT);
How can I retrieve the statement after the binding? A string I could echo
is fine.
Solution
The in
statement will not work. One method is to include the list directly in the SQL (yucky, but that is the approach). Another is to use find_in_set()
:
WHERE find_in_set(Order_SG.Server__, :servers) > 0 AND
. . .
However, an index cannot be used for this function.
Answered By - Gordon Linoff Answer Checked By - David Goodson (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.