This appendix shows a version of the page script from Appendix B after being converted to use Gateway classes. Note how very little of it has changed. Even though the SQL statements have been removed, the domain business logic remains embedded in the page script.
The Gateway classes are provided below the page script, and show a conversion to PDO-style bound parameters. Also note that there have been minor modifications to the
if() conditions in the page script: whereas previously they checked to see if a query succeeded, they now check for a return value from the Gateway.
page_script.php <?php 2 // ... $user_id value created earlier 3 4 $db = new Database($db_host, $db_user, $db_pass); 5 $articles_gateway = new ...