Skip to content

Instantly share code, notes, and snippets.

@shawnlindstrom
Created October 28, 2022 04:00
Show Gist options
  • Save shawnlindstrom/46ec3710d50fbacffbd7699b26cd1dee to your computer and use it in GitHub Desktop.
Save shawnlindstrom/46ec3710d50fbacffbd7699b26cd1dee to your computer and use it in GitHub Desktop.
Using PDO from the DB facade for a complex query
$sql = "SELECT tblSU.Site,
tlkpSUDesc.ESR_SUcat,
tlkpSUDesc.ESR_SUcatdisp,
tlkpSUDesc.SUDesc,
tlkpSUTyp.SUTyp,
tblSU.SUNum
FROM tlkpSUTyp
RIGHT JOIN (tlkpSUDesc RIGHT JOIN tblSU ON tlkpSUDesc.SUDescCode = tblSU.SUDescCode)
ON tlkpSUTyp.SUTypCode = tblSU.SUTypCode
WHERE tblSU.Site = :id
AND tlkpSUDesc.ESR_SUcat = :category
AND tblSU.SUTypCode != 'GEN'
ORDER BY tblSU.Site, tlkpSUDesc.ESR_SUcatdisp, tblSU.SUDescCode";
$statement = \DB::getPdo()->prepare($sql);
$statement->setFetchMode(\PDO::FETCH_OBJ);
$statement->execute([
'id' => $id,
'category' => $category
]);
$result = collect($statement->fetchAll());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment