[ class tree: DB ] [ index: DB ] [ all elements ]

Class: DB

Source Location: /DB-1.7.14/DB.php

Class Overview

Database independent query interface



  • Release: 1.7.14


  • 1997-2007 The PHP Group


Inherited Variables

Inherited Methods

Class Details

[line 432]
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

[ Top ]

Method Detail

apiVersion   [line 577]

string apiVersion( )

Return the DB API version
  • Return: the DB API version number

[ Top ]

connect   [line 518]

object a &connect( mixed $dsn, [array $options = array()])

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

Example 1.

  1.  require_once 'DB.php';
  3.  $dsn 'pgsql://user:password@host/database';
  4.  $options = array(
  5.      'debug'       => 2,
  6.      'portability' => DB_PORTABILITY_ALL,
  7.  );
  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()


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

[ Top ]

errorMessage   [line 652]

string errorMessage( integer $value)

Return a textual error message for a DB error code
  • Return: the error message or false if the error code was not recognized


integer   $value     the DB error code

[ Top ]

factory   [line 447]

object a &factory( string $type, [array $options = false])

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


string   $type     the database type (eg "mysql")
array   $options     an associative array of option names and values

[ Top ]

getDSNString   [line 862]

string getDSNString( array|string $dsn, boolean $hidePassword)

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


array|string   $dsn     the DSN to parse and format
boolean   $hidePassword     true to hide the password, false to include it

[ Top ]

isConnection   [line 607]

bool isConnection( mixed $value)

Determines if a value is a DB_<driver> object
  • Return: whether $value is a DB_<driver> object


mixed   $value     the value to test

[ Top ]

isError   [line 592]

bool isError( mixed $value)

Determines if a variable is a DB_Error object
  • Return: whether $value is DB_Error object


mixed   $value     the variable to check

[ Top ]

isManip   [line 628]

boolean isManip( string $query)

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


string   $query     the query

[ Top ]

parseDSN   [line 733]

array parseDSN( string $dsn)

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


string   $dsn     Data Source Name to be parsed

[ Top ]

Documentation generated on Sat, 27 Aug 2011 14:00:07 +0000 by phpDocumentor 1.4.3. PEAR Logo Copyright © PHP Group 2004.