/include/database.php

Description

Database functions and classes.

$Id: database.php 594 2006-03-20 11:12:42Z stijn $

Constants
DB_NOT_CONNECTED = -2 (line 34)

Database connection failed status code.

Status code returned by db_mysql::connect and db_postgresl::connect when the database connection could not be made; an invalid combination of databasename/user/password was given or the database user lacks permissions.

DB_NOT_SUPPORTED = -1 (line 26)

Database type not supported status code.

Status code returned by db_mysql::connect and db_postgresl::connect when the configured database was of a type that was not supported by the current installation of PHP.

DB_OK = 1 (line 19)

Database connection ok status code.

Status code returned by db_mysql::connect and db_postgresl::connect when the database connection was succesfully created.

FETCH_ASSOC = 1 (line 48)

Use only associative arrays for query result sets.

Method indicator for db_mysql::fetch_array and db_postgresql::fetch_array. The resulting array will be returned as a purely associative array.

FETCH_BOTH = 3 (line 61)

Use both associative and numerical indices for query result sets.

Method indicator for db_mysql::fetch_array and db_postgresql::fetch_array. The resulting array will be returned as an array wich both numerically and associatively indexes the rows of the result set.

FETCH_NEXTROW = -1 (line 70)

Next row value.

Indicates that the caller wants to fetch the next row to db_mysql::fetch_array or db_postgresql::fetch_array.

FETCH_NUM = 2 (line 54)

Use a numerically indexed array for query result sets.

Method indicator for db_mysql::fetch_array and db_postgresql::fetch_array. The resulting array will be returned as a purely numerically indexed array.

Functions
db_get_object (line 244)

Return a connected database object.

This is the master function to connect to a database. Based on a database name, it returns either an error code or a connected database object.

The database name is actually the name of an SWS database configuration file, in which the actual parameters for connecting to the database are defined. See db_get_parameters for details about the configuration file location. See $swsroot/etc/db.example for an example of the syntax.

This function caches the connection per request. The first call will initiate the connection to the database and the connection will persist until the request has been completed or the db_mysql::close method is called to close the connection explicitly. Note that in the last case, it is not possible to reconnect to the same database on the same request!

  • return: connected database object
object the db_get_object (string $dbname)
  • string $dbname: database alias to connect to
db_get_parameters (line 92)

Retrieve configured database parameters for a database.

This function returns an associative array of parameters for a specific database, as configured by the system.

Configuration files are searched for in SWSCONFIGDIR/db, and then in $swsrootdir/etc/db, in that order.

The following keys are present in the resulting array:

  • type, the type of database (mysql, postgresql)
  • host, the database server hostname
  • name, the name of the database
  • user, the database user name
  • password, the database user password

  • return: an associative array with database parameters.
array db_get_parameters (string $dbname)
  • string $dbname: the name of the database configuration file
db_get_sws_privileged_object (line 299)

Returns a privileged connection to the SWS database. Obviously only works if the caller is allowed access (this might not be the case in a secure virtual host setup).

  • return: a database object representing the SWS database, or FALSE if access was denied
object db_get_sws_privileged_object ()

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