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

Class: Creole

Source Location: /creole/Creole.php

Class Overview


This is the class that manages the database drivers.


Author(s):

Version:

  • $Revision: 1.7 $

Constants

Methods



Class Details

[line 46]
This is the class that manages the database drivers.

There are a number of default drivers (at the time of writing this comment: MySQL, MSSQL, SQLite, PgSQL, Oracle) that are "shipped" with Creole. You may wish to either add a new driver or swap out one of the existing drivers for your own custom driver. To do this you simply need to register your driver using the registerDriver() method.

Note that you register your Connection class because the Connection class is responsible for calling the other driver classes (e.g. ResultSet, PreparedStatement, etc.).




Tags:

version:  $Revision: 1.7 $
author:  Hans Lellelid <hans@xmpl.org>


[ Top ]


Class Methods


method deregisterDriver [line 111]

void deregisterDriver( string $phptype)

Removes the driver for a PHP type. Note that this will remove user-registered drivers _and_ the default drivers.



Tags:

static:  
access:  public
see:  Creole::registerDriver()


Parameters:

string   $phptype   The PHP type for driver to de-register.

[ Top ]

method getConnection [line 145]

Connection getConnection( mixed $dsn, [int $flags = 0])

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



Tags:

return:  Newly created DB connection object
static:  
access:  public
see:  self::parseDSN()
throws:  SQLException


Parameters:

mixed   $dsn   "data source name", see the self::parseDSN method for a description of the dsn format. Can also be specified as an array of the format returned by DB::parseDSN().
int   $flags   Connection flags (e.g. PERSISTENT).

[ Top ]

method getDriver [line 122]

string getDriver( string $phptype)

Returns the class path to the driver registered for specified type.



Tags:

return:  The driver class in dot-path notation (e.g. creole.drivers.mssql.MSSQLConnection) or NULL if no registered driver found.
static:  
access:  public


Parameters:

string   $phptype   The phptype handled by driver (e.g. 'mysql', 'mssql', '*').

[ Top ]

method import [line 282]

string import( string $class)

Include once a file specified in DOT notation.

Package notation is expected to be relative to a location on the PHP include_path.




Tags:

return:  unqualified classname
static:  
access:  public
throws:  SQLException - if class does not exist and cannot load file
  • if after loading file class still does not exist


Parameters:

string   $class  

[ Top ]

method parseDSN [line 214]

array parseDSN( string $dsn)

Parse a data source name.

This isn't quite as powerful as DB::parseDSN(); it's also a lot simpler, a lot faster, and many fewer lines of code.

A array with the following keys will be returned: phptype: Database backend used in PHP (mysql, odbc 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

The format of the supplied DSN is in its fullest form:

phptype://username:password@protocol+hostspec/database

Most variations are allowed:

phptype://username:password@protocol+hostspec:110//usr/db_file.db phptype://username:password@hostspec/database_name phptype://username:password@hostspec phptype://username@hostspec phptype://hostspec/database phptype://hostspec phptype




Tags:

return:  An associative array
static:  
access:  public


Parameters:

string   $dsn   Data Source Name to be parsed

[ Top ]

method registerDriver [line 100]

void registerDriver( string $phptype, string $dotpath)

Register your own RDBMS driver class.

You can use this to specify your own class that replaces a default driver or adds support for a new driver. Register your own class by specifying the 'phptype' (e.g. mysql) and a dot-path notation to where your Connection class is relative to any location on the include path. You can also specify '*' as the phptype if you want to register a driver that will handle any native type (e.g. if creating a set of decorator classes that log SQL before calling native driver methods). YOU CAN ONLY REGISTER ONE CATCHALL ('*') DRIVER. <p> Note: the class you need to register is your Connection class because this is the class that's responsible for instantiating the other classes that are part of your driver. It is possible to mix & match drivers -- i.e. to write a custom driver where the Connection object just instantiates stock classes for ResultSet and PreparedStatement. Note that if you wanted to "override" only the ResultSet class you would also have to override the Connection and PreparedStatement classes so that they would return the correct ResultSet class. In the future we may implement a more "packaged" approach to drivers; for now we want to keep it simple.




Tags:

static:  
access:  public


Parameters:

string   $phptype   The phptype (mysql, mssql, etc.). This is first part of DSN URL (e.g. mysql://localhost/...). You may also specify '*' to register a driver that will "wrap" the any native drivers.
string   $dotpath   A dot-path locating your class. For example 'creole.drivers.mssql.MSSQLConnection' will be included like: include 'creole/drivers/mssql/MSSQLConnection.php' and the classname will be assumed to be 'MSSQLConnection'.

[ Top ]


Class Constants

NO_ASSOC_LOWER =  16

[line 57]

Flag to pass to the connection to indicate that no case conversions should be performed by ResultSet on keys of fetched rows.


[ Top ]

PERSISTENT =  1

[line 51]

Constant that indicates a connection object should be used.


[ Top ]



Documentation generated on Mon, 23 Aug 2004 21:51:20 -0400 by phpDocumentor 1.3.0RC3