Previous Up Next
The framework Introduction Authentication
Database access

Database access

SWS database access documentation

Database access

SWS includes its own functions for abstracting database access. While PEAR could have been used, at the time SWS was written that was still in its infancy. Also, PEAR was still starting to get momentum, but was not really useful in the authors eyes. At any rate, the database access is abstracted using the following API.

db_get_object

The db_get_object function is the heart of the SWS database system. It returns a database object that is connected to the database as specified in the database configuration file with the name $dbname.

This function will cache connections. Multiple invocations with the same $dbname (on the same request) will return the same database object.

Connections are intentionally created anew with every request. While resource-intensive, there is good reason for this, as recycling connections has in the past led to race conditions and other hard-to-debug problems.

$db object

The $db object is an instantiation of the SWS database class. It contains methods to do queries on the underlying database. It tries to abstract the underlying database system without precluding customization. It contains the following methods:

  • db_mysql::query

  • db_mysql::quote

  • db_mysql::close

  • db_mysql::begin_transaction

  • db_mysql::commit

  • db_mysql::rollback

  • db_mysql::query_count

$result object

The $result object is an instantiation of the SWS database result class. It contains methods to access the recordsets of the query result. It contains the following methods:

  • db_mysql_result::num_rows

  • db_mysql_result::fetch_array

  • db_mysql_result::affected_rows

  • db_mysql_result::last_insert_id

  • db_mysql_result::num_fields

  • db_mysql_result::field_name

  • db_mysql_result::field_type

  • db_mysql_result::free_result

Previous Up Next
The framework Introduction Authentication

Documentation generated on Fri, 30 Jun 2006 10:31:36 +0200 by phpDocumentor 1.3.0RC3