Databases

Sodapop accesses databases through wrappers that provide a consistent interface to PHP's various database libraries. It uses subclasses of Sodapop_Database_Abstract, of which Sodapop_Database_Pdo is the first implementation.

Getting a Connection Reference

Sodapop manages its connections through the Application object.

Querying the Database

Sodapop supports both executing arbitrary SQL strings, as well as prepared statements. If the particular underlying PHP driver doesn't support prepared statements, the syntax will still work; Sodapop will simply convert the query into a regular SQL string. Results are always arrays of associative arrays.

Updating the Database

Sodapop similarly supports updating the database via building SQL strings and prepared statements. If the particular underlying PHP driver doesn't support prepared statements, the syntax will still work; Sodapop will simply convert the query into a regular SQL string. The methods don't have return values but can throw exceptions on error.

Creating a New Connection

Sodapop (usually) has a default database connection that is specified in the sodapop.json file. It is also possible to make other connections as needed if an application needs to utilize multiple databases.

Please note: The code below is not necessary for the database connection specified in sodapop.json. The framework connects to that database automatically.

Adding Support for Other Databases

At this time Sodapop supports MySQL through the PHP PDO driver.

If necessary, it is straightforward to add support for new databases and database drivers; there are 7 primary abstract methods in Sodapop_Database_Abstract that need to be written. The source code for /Sodapop/Database/Pdo.php provides a great starting point for anyone looking to add support for a new database.

Public Methods

lastInsertId() (int)
Returns the last autogenerated insert ID.
runParameterizedQuery($query, $parameters = array()) (array)
Runs a parameterized query on the database, replacing the named parameters with those in the supplied array.
runParameterizedUpdate($update, $parameters = array()) (boolean)
Runs a parameterized update on the database, replacing the named parameters with those in the supplied array.
runQuery($query) (array)
Runs a query on the database.
runUpdate($update) (boolean)
Runs an update on the database.