Created
October 28, 2022 04:00
-
-
Save shawnlindstrom/46ec3710d50fbacffbd7699b26cd1dee to your computer and use it in GitHub Desktop.
Using PDO from the DB facade for a complex query
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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