SQL Data Access API: SQL Databases Support Driver
This API wraps PDO native library in order to overcome latter's poor design (eg: lack of data source encapsulation) and build a flexible object oriented structure on top of it.
How does it work?
The purpose of refactoring PDO functionality isn’t just to overcome PDO design flaws, but also to bring unity and structure to the process of communication with a database server. In light of above observations on PDO library, functionality is divided into following classes:
- DataSource: encapsulates data required in connecting to a database server.
- Connection: manages connection related operations based on DataSource
- Transaction: manages transaction related operations.
- Statement: manages statement execution operations.
- PreparedStatement: manages statement preparation and execution operations.
- StatementResults: manages information to be retrieved following statement execution.
When an error is encountered, exceptions specific to event are thrown:
- ConnectionException: thrown when connection to server fails.
- StatementException: thrown when statement execution fails.
Almost always we also desire to reuse created connection for other queries throughout user session's duration and also make sure that connection is automatically closed when session ends. For this two classes were added:
- ConnectionSingleton: insures a single connection is created, then reused by all queries throughout session's duration, then closed when session ends. This is useful when you're only using one SQL server during session's lifetime.
- ConnectionFactory: insures a single connection is created for each server, then reused by all queries on that server throughout session's duration, then closed when session ends. This is useful when you're using more than one SQL server during session's lifetime.
All classes inside API belong to namespace Lucinda\SQL!
How can I use it?
To learn how to install and use this API, follow this step-by-step guide!