| Design Patterns
We can solve these problems by writing:
$statement = $sql->get("FIND_ISBN", { title => "Design Patterns" }); $sth = $dbh->prepare($statement); $rc=$sth->execute();
|
- SQL referenced by a key
- Statement parameters passed separately
The SQL statements and their corresponding lookup keys are then stored in a separate place that we call a phrasebook. We can use XML to wrap the SQL and the lookup keys:
<phrase name="FIND_ISBN"> select isbn from book where title = '$title' </phrase>
|
- The SQL statement can hold placeholders, so we can use one generic SQL statement that can be used in different places.
Now, our code is more readable and maintainable.
|