Class DB

Description

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.

  • version: $Id: DB.php,v 1.59 2004/07/08 21:15:11 danielc Exp $
  • since: PHP 4.0
  • author: Stig Bakken <ssb@php.net>
  • author: Tomas V.V.Cox <cox@idecnet.com>

Located in /maintenance/libraries/pear/DB.php (line 270)


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

Return the DB API version

  • return: the DB API version number
  • access: public
int apiVersion ()
assertExtension (line 705)

Load a PHP database extension if it is not loaded already.

  • return: true if the extension was already or successfully loaded, false if it could not be loaded
  • access: public
boolean assertExtension (string $name)
  • string $name: the base name of the extension (without the .so or .dll suffix)
connect (line 356)

Create a new DB object and connect to the specified database.

Example 1.

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

object a &connect (mixed $dsn, [array $options = array()])
  • mixed $dsn: string "data source name" or an array in the format returned by DB::parseDSN()
  • array $options: an associative array of option names and their values
errorMessage (line 488)

Return a textual error message for a DB error code

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

Create a new DB object for the specified database type.

Allows creation of a DB_<driver> object from which the object's methods can be utilized without actually connecting to a database.

object a &factory (string $type, [array $options = false])
  • string $type: database type, for example "mysql"
  • array $options: associative array of option names and values
isConnection (line 446)

Tell whether a value is a DB connection

  • return: whether $value is a DB connection
  • access: public
bool isConnection (mixed $value)
  • mixed $value: value to test
isError (line 429)

Tell whether a result code from a DB method is an error

  • return: whether $value is an error
  • access: public
bool isError (int $value)
  • int $value: result code
isManip (line 467)

Tell whether a query is a data manipulation query (insert, update or delete) or a data definition query (create, drop, alter, grant, revoke).

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

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):

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
  • author: Tomas V.V.Cox <cox@idecnet.com>
array parseDSN (string $dsn)
  • string $dsn: Data Source Name to be parsed

Documentation generated on Fri, 24 Dec 2004 13:01:51 +0000 by phpDocumentor 1.3.0RC3