[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
class.
apiVersion [line 578]
Return the DB API version
- Return: the DB API version number
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. require_once 'DB.php';
$dsn = 'pgsql://user:password@host/database';
$options = array(
'debug' => 2,
);
if (PEAR::isError($db)) {
die($db->getMessage());
}
- Return: new DB object. A DB_Error object on failure.
- Access: public
- 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()
Parameters:
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 653]
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
- Access: public
Parameters:
integer
$value
—
the DB error code
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
Parameters:
string
$type
—
the database type (eg "mysql")
array
$options
—
an associative array of option names and values
getDSNString [line 863]
string getDSNString(
array|string
$dsn, boolean
$hidePassword)
Returns the given DSN in a string format suitable for output.
Parameters:
array|string
$dsn
—
the DSN to parse and format
boolean
$hidePassword
—
true to hide the password, false to include it
isConnection [line 608]
bool isConnection(
mixed
$value)
Determines if a value is a DB_<driver> object
- Return: whether $value is a DB_<driver> object
- Access: public
Parameters:
mixed
$value
—
the value to test
isError [line 593]
bool isError(
mixed
$value)
Determines if a variable is a DB_Error object
- Return: whether $value is DB_Error object
- Access: public
Parameters:
mixed
$value
—
the variable to check
isManip [line 629]
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
- Access: public
Parameters:
string
$query
—
the query
parseDSN [line 734]
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: phptype(dbsyntax)://username:password@protocol+hostspec/database?option=8&another=true
Most variations are allowed: 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
- 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
- Access: public
Parameters:
string
$dsn
—
Data Source Name to be parsed