Chapter 11. A Universal Class for Connections and a Proxy Pattern for Security
It is art that makes life, makes interest, makes importance... and I know of no substitute whatever for the force and beauty of its process.
Substitute “damn” every time you’re inclined to write “very”; your editor will delete it and the writing will be just as it should be.
The work of science is to substitute facts for appearances, and demonstrations for impressions.
A Simple Interface and Class for MySQL
In Chapter 2, you saw one
example of how PHP allows interfaces to store constants that can be used
by classes that implement the interface. One set of constants that can be
stored in the interface is that required for connecting to a MySQL
database. The routine using the PHP mysqli
extension provides some variations for
connection, but all variations need the host, username, password, and
database information. Once the routine is set in a class, it should be
available for general reuse whenever a program requires a MySQL
connection. Figure 11-1 shows the
class diagram for this arrangement.
Figure 11-1. Universal MySQL class diagram
The connection information is independent of the client because the
concrete information is stored in constants in the interface. The UniversalConnect
class uses the Scope Resolution Operator to access the data stored in the constants in the interface. ...
Get Learning PHP Design Patterns now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.