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

Class: DB

Source Location: /DB-1.6.2/DB.php

Class Overview


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.


Author(s):

Version:

  • $Id: DB.php,v 1.58 2004/03/13 16:17:19 danielc Exp $

Methods


Inherited Variables

Inherited Methods


Class Details

[line 270]
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.

  • Author: Tomas V.V.Cox <cox@idecnet.com>
  • Author: Stig Bakken <ssb@php.net>
  • Version: $Id: DB.php,v 1.58 2004/03/13 16:17:19 danielc Exp $
  • Since: PHP 4.0


[ Top ]


Method Detail

apiVersion   [line 412]

int apiVersion( )

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

[ Top ]

assertExtension   [line 705]

boolean assertExtension( string $name)

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

Parameters:

string   $name   —  the base name of the extension (without the .so or .dll suffix)

[ Top ]

connect   [line 356]

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

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.  ?>


Parameters:

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

[ Top ]

errorMessage   [line 488]

string errorMessage( integer $value)

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

Parameters:

integer   $value   —  error code

[ Top ]

factory   [line 288]

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

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.


Parameters:

string   $type   —  database type, for example "mysql"
array   $options   —  associative array of option names and values

[ Top ]

isConnection   [line 446]

bool isConnection( mixed $value)

Tell whether a value is a DB connection
  • Return: whether $value is a DB connection
  • Access: public

Parameters:

mixed   $value   —  value to test

[ Top ]

isError   [line 429]

bool isError( int $value)

Tell whether a result code from a DB method is an error
  • Return: whether $value is an error
  • Access: public

Parameters:

int   $value   —  result code

[ Top ]

isManip   [line 467]

boolean isManip( string $query)

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

Parameters:

string   $query   —  the query

[ Top ]

parseDSN   [line 571]

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
  • Author: Tomas V.V.Cox <cox@idecnet.com>

Parameters:

string   $dsn   —  Data Source Name to be parsed

[ Top ]


Documentation generated on Mon, 11 Mar 2019 10:14:51 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.