Class DB

Description

Database independent query interface

The main "DB" class is simply a container class with some static methods for creating DB objects as well as some utility functions common to all parts of DB.

The object model of DB is as follows (indentation means inheritance):

 DB           The main DB class.  This is simply a utility class
              with some "static" methods for creating DB objects as
              well as common utility functions for other DB classes.

 DB_common    The base for each DB implementation.  Provides default
 |            implementations (in OO lingo virtual methods) for
 |            the actual DB implementations as well as a bunch of
 |            query utility functions.
 |
 +-DB_mysql   The DB implementation for MySQL.  Inherits DB_common.
              When calling DB::factory or DB::connect for MySQL
              connections, the object returned is an instance of this
              class.

Located in /web/lib/external/pear-db/DB.php (line 434)


	
			
Method Summary
 string apiVersion ()
 object a &connect (mixed $dsn, [array $options = array()])
 string errorMessage (integer $value)
 object a &factory (string $type, [array $options = false])
 string getDSNString (array|string $dsn, boolean $hidePassword)
 bool isConnection (mixed $value)
 bool isError (mixed $value)
 boolean isManip (string $query)
 array parseDSN (string $dsn)
Methods
apiVersion (line 579)

Return the DB API version

  • return: the DB API version number
string apiVersion ()
connect (line 520)

Create a new DB object including a connection to the specified database

Example 1.

  1.  require_once 'DB.php';
  2.  
  3.  $dsn 'pgsql://user:password@host/database';
  4.  $options array(
  5.      'debug'       => 2,
  6.      'portability' => DB_PORTABILITY_ALL,
  7.  );
  8.  
  9.  $db =DB::connect($dsn$options);
  10.  if (PEAR::isError($db)) {
  11.      die($db->getMessage());
  12.  }

  • return: new DB object. A DB_Error object on failure.
  • uses: DB_dbase::connect(), - DB_fbsql::connect(), DB_ibase::connect(), DB_ifx::connect(), DB_msql::connect(), DB_mssql::connect(), DB_mysql::connect(), DB_mysqli::connect(), DB_oci8::connect(), DB_odbc::connect(), DB_pgsql::connect(), DB_sqlite::connect(), DB_sybase::connect()
  • uses: DB::parseDSN(), - DB_common::setOption(), PEAR::isError()
object a &connect (mixed $dsn, [array $options = array()])
  • mixed $dsn: the string "data source name" or array in the format returned by DB::parseDSN()
  • array $options: an associative array of option names and values
errorMessage (line 654)

Return a textual error message for a DB error code

  • return: the error message or false if the error code was not recognized
string errorMessage (integer $value)
  • integer $value: the DB error code
factory (line 449)

Create a new DB object for the specified database type but don't connect to the database

object a &factory (string $type, [array $options = false])
  • string $type: the database type (eg "mysql")
  • array $options: an associative array of option names and values
getDSNString (line 864)

Returns the given DSN in a string format suitable for output.

string getDSNString (array|string $dsn, boolean $hidePassword)
  • array|string $dsn: the DSN to parse and format
  • boolean $hidePassword: true to hide the password, false to include it
isConnection (line 609)

Determines if a value is a DB_<driver> object

  • return: whether $value is a DB_<driver> object
bool isConnection (mixed $value)
  • mixed $value: the value to test
isError (line 594)

Determines if a variable is a DB_Error object

  • return: whether $value is DB_Error object
bool isError (mixed $value)
  • mixed $value: the variable to check
isManip (line 630)

Tell whether a query is a data manipulation or data definition query

Examples of data manipulation queries are INSERT, UPDATE and DELETE. Examples of data definition queries are CREATE, DROP, ALTER, GRANT, REVOKE.

  • return: whether $query is a data manipulation query
boolean isManip (string $query)
  • string $query: the query
parseDSN (line 735)

Parse a data source name

Additional keys can be added by appending a URI query string to the end of the DSN.

The format of the supplied DSN is in its fullest form:

  1.   phptype(dbsyntax)://username:password@protocol+hostspec/database?option=8&another=true

Most variations are allowed:

  1.   phptype://username:password@protocol+hostspec:110//usr/db_file.db?mode=0644
  2.   phptype://username:password@hostspec/database_name
  3.   phptype://username:password@hostspec
  4.   phptype://username@hostspec
  5.   phptype://hostspec/database
  6.   phptype://hostspec
  7.   phptype(dbsyntax)
  8.   phptype

  • return: an associative array with the following keys:
    • phptype: Database backend used in PHP (mysql, odbc etc.)
    • dbsyntax: Database used with regards to SQL syntax etc.
    • protocol: Communication protocol to use (tcp, unix etc.)
    • hostspec: Host specification (hostname[:port])
    • database: Database to use on the DBMS server
    • username: User name for login
    • password: Password for login
array parseDSN (string $dsn)
  • string $dsn: Data Source Name to be parsed

Documentation generated on Wed, 09 Feb 2011 08:59:18 +0700 by phpDocumentor 1.4.2