[ Index ]
 

Code source de PHP PEAR 1.4.5

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/ -> DB.php (sommaire)

Database independent query interface PHP versions 4 and 5

Author: Stig Bakken <ssb@php.net>
Author: Tomas V.V.Cox <cox@idecnet.com>
Author: Daniel Convissor <danielc@php.net>
Copyright: 1997-2005 The PHP Group
License: http://www.php.net/license/3_0.txt PHP License 3.0
Version: CVS: $Id: DB.php,v 1.86 2007/01/22 01:17:48 aharvey Exp $
Poids: 1489 lignes (43 kb)
Inclus ou requis: 9 fois
Référencé: 0 fois
Nécessite: 1 fichier
 PEAR.php

Définit 4 classes

DB:: (9 méthodes):
  factory()
  connect()
  apiVersion()
  isError()
  isConnection()
  isManip()
  errorMessage()
  parseDSN()
  getDSNString()

DB_Error:: (1 méthode):
  DB_Error()

DB_result:: (11 méthodes):
  DB_result()
  setOption()
  fetchRow()
  fetchInto()
  numCols()
  numRows()
  nextResult()
  free()
  tableInfo()
  getQuery()
  getRowCounter()

DB_row:: (1 méthode):
  DB_row()


Classe: DB  - X-Ref

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):
<pre>
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.
</pre>

factory($type, $options = false)   X-Ref
Create a new DB object for the specified database type but don't
connect to the database

param: string $type     the database type (eg "mysql")
param: array  $options  an associative array of option names and values
return: object  a new DB object.  A DB_Error object on failure.

connect($dsn, $options = array()   X-Ref
Create a new DB object including a connection to the specified database

Example 1.
<code>
require_once 'DB.php';

$dsn = 'pgsql://user:password@host/database';
$options = array(
'debug'       => 2,
'portability' => DB_PORTABILITY_ALL,
);

$db =& DB::connect($dsn, $options);
if (PEAR::isError($db)) {
die($db->getMessage());
}
</code>

param: mixed $dsn      the string "data source name" or array in the
param: array $options  an associative array of option names and values
return: object  a new DB object.  A DB_Error object on failure.

apiVersion()   X-Ref
Return the DB API version

return: string  the DB API version number

isError($value)   X-Ref
Determines if a variable is a DB_Error object

param: mixed $value  the variable to check
return: bool  whether $value is DB_Error object

isConnection($value)   X-Ref
Determines if a value is a DB_<driver> object

param: mixed $value  the value to test
return: bool  whether $value is a DB_<driver> object

isManip($query)   X-Ref
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.

param: string $query  the query
return: boolean  whether $query is a data manipulation query

errorMessage($value)   X-Ref
Return a textual error message for a DB error code

param: integer $value  the DB error code
return: string  the error message or false if the error code was

parseDSN($dsn)   X-Ref
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:
<code>
phptype(dbsyntax)://username:password@protocol+hostspec/database?option=8&another=true
</code>

Most variations are allowed:
<code>
phptype://username:password@protocol+hostspec:110//usr/db_file.db?mode=0644
phptype://username:password@hostspec/database_name
phptype://username:password@hostspec
phptype://username@hostspec
phptype://hostspec/database
phptype://hostspec
phptype(dbsyntax)
phptype
</code>

param: string $dsn Data Source Name to be parsed
return: array an associative array with the following keys:

getDSNString($dsn, $hidePassword)   X-Ref
Returns the given DSN in a string format suitable for output.

param: array|string the DSN to parse and format
param: boolean true to hide the password, false to include it
return: string

Classe: DB_Error  - X-Ref

DB_Error implements a class for reporting portable database error
messages

DB_Error($code = DB_ERROR, $mode = PEAR_ERROR_RETURN,$level = E_USER_NOTICE, $debuginfo = null)   X-Ref
DB_Error constructor

param: mixed $code       DB error code, or string with error message
param: int   $mode       what "error mode" to operate in
param: int   $level      what error level to use for $mode &
param: mixed $debuginfo  additional debug info, such as the last query

Classe: DB_result  - X-Ref

This class implements a wrapper for a DB result set

A new instance of this class will be returned by the DB implementation
after processing a query that returns data.

DB_result(&$dbh, $result, $options = array()   X-Ref
This constructor sets the object's properties

param: object   &$dbh     the DB object reference
param: resource $result   the result resource id
param: array    $options  an associative array with result options
return: void

setOption($key, $value = null)   X-Ref
Set options for the DB_result object

param: string $key    the option to set
param: mixed  $value  the value to set the option to
return: void

fetchRow($fetchmode = DB_FETCHMODE_DEFAULT, $rownum = null)   X-Ref
Fetch a row of data and return it by reference into an array

The type of array returned can be controlled either by setting this
method's <var>$fetchmode</var> parameter or by changing the default
fetch mode setFetchMode() before calling this method.

There are two options for standardizing the information returned
from databases, ensuring their values are consistent when changing
DBMS's.  These portability options can be turned on when creating a
new DB object or by using setOption().

+ <var>DB_PORTABILITY_LOWERCASE</var>
convert names of fields to lower case

+ <var>DB_PORTABILITY_RTRIM</var>
right trim the data

param: int $fetchmode  the constant indicating how to format the data
param: int $rownum     the row number to fetch (index starts at 0)
return: mixed  an array or object containing the row's data,

fetchInto(&$arr, $fetchmode = DB_FETCHMODE_DEFAULT, $rownum = null)   X-Ref
Fetch a row of data into an array which is passed by reference

The type of array returned can be controlled either by setting this
method's <var>$fetchmode</var> parameter or by changing the default
fetch mode setFetchMode() before calling this method.

There are two options for standardizing the information returned
from databases, ensuring their values are consistent when changing
DBMS's.  These portability options can be turned on when creating a
new DB object or by using setOption().

+ <var>DB_PORTABILITY_LOWERCASE</var>
convert names of fields to lower case

+ <var>DB_PORTABILITY_RTRIM</var>
right trim the data

param: array &$arr       the variable where the data should be placed
param: int   $fetchmode  the constant indicating how to format the data
param: int   $rownum     the row number to fetch (index starts at 0)
return: mixed  DB_OK if a row is processed, NULL when the end of the

numCols()   X-Ref
Get the the number of columns in a result set

return: int  the number of columns.  A DB_Error object on failure.

numRows()   X-Ref
Get the number of rows in a result set

return: int  the number of rows.  A DB_Error object on failure.

nextResult()   X-Ref
Get the next result if a batch of queries was executed

return: bool  true if a new result is available or false if not

free()   X-Ref
Frees the resources allocated for this result set

return: bool  true on success.  A DB_Error object on failure.

tableInfo($mode = null)   X-Ref


getQuery()   X-Ref
Determine the query string that created this result

return: string  the query string

getRowCounter()   X-Ref
Tells which row number is currently being processed

return: integer  the current row being looked at.  Starts at 1.

Classe: DB_row  - X-Ref

PEAR DB Row Object

The object contains a row of data from a result set.  Each column's data
is placed in a property named for the column.

DB_row(&$arr)   X-Ref
The constructor places a row's data into properties of this object

param: array  the array containing the row's data
return: void



Généré le : Sun Feb 25 14:08:00 2007 par Balluche grâce à PHPXref 0.7