Show:

Db Class

Module: Db

Abstract class for database connection

Item Index

Methods

Methods

autoload

(
  • $class_name
)
static

If Db is used a standalone library, then this autoloader will be used after you call Db::registerAutoload()

Parameters:

  • $class_name String

connect

(
  • $conn_name
)
Db_Interface static

This function uses Db to establish a connection with the information stored in the configuration. If the this Db object has already been made, it returns this Db object.

Note: THIS FUNCTION NO LONGER CREATES A CONNECTION RIGHT OFF THE BAT. Instead, the real connection (PDO object) is only made when it is necessary (for example, when a query is executed).

Parameters:

  • $conn_name String

    The name of the connection out of the connections added with Db::setConnection

Returns:

exportArray

(
  • $what
  • $options
)
String static

Returns an array for outputting to client.

Parameters:

  • $what Mixed

    Could be a (multidimensional) array of Db_Row objects or a Db_Row object

  • $options Array

    Options for row exportArray methods. Can also include the following:

    • [numeric] Boolean optional

      Makes a plain numerically indexed array, even if $what has keys

Returns:

String:

fromDate

(
  • $syntax
  • $datetime
)
String static

Returns a timestamp from a Date string For backward compatibility. Works with MySQL and hopefully lots of other databases.

Parameters:

  • $syntax String

    The format of the date string, see {@link date()} function.

  • $datetime String

    The DateTime string that comes from the db

Returns:

String:

The timestamp

fromDateTime

(
  • $datetime
)
String static

Returns a timestamp from a DateTime string For backward compatibility. Works with MySQL and hopefully lots of other databases.

Parameters:

  • $datetime String

    The DateTime string that comes from the db

Returns:

String:

The timestamp

generateTableClassName

(
  • $table_name
  • $connection_name=null
)
String static

Generates a class name given a table name

Parameters:

  • $table_name String
  • $connection_name=null String

Returns:

String:

getConnection

(
  • $name
)
Array | Null static

Returns connection details for a connection

Parameters:

  • $name String

Returns:

Array | Null:

getConnections

() Array static

Returns all the connections added thus far

Returns:

Array:

getShard

(
  • $conn_name
  • $shard_name
)
Array | Null static

Returns modification details for a shard pertaining to a connection

Parameters:

  • $conn_name String
  • $shard_name String

Returns:

Array | Null:

getShards

(
  • $conn_name
)
Array deprecated static

Defined in platform/classes/Db.php:458

Deprecated: Shards configuration is maintained via config

Returns all the shards added thus far for a connection

Parameters:

  • $conn_name String

Returns:

Array:

hash

(
  • $text
)
String static

Hashes text in a standard way.

Parameters:

  • $text String

Returns:

String:

The hash string

normalize

(
  • $text
  • $replacement='_'
  • $characters=null
  • $numChars=233
)
static

Normalizes text by converting it to lower case, and replacing all non-accepted characters with underscores.

Parameters:

  • $text String

    The text to normalize

  • $replacement='_' String

    Defaults to '_'. A string to replace one or more unacceptable characters. You can also change this default using the config Db/normalize/replacement

  • $characters=null String

    Defaults to '/[^A-Za-z0-9]+/'. A regexp characters that are not acceptable. You can also change this default using the config Db/normalize/characters

  • $numChars=233 Integer

parseDsnString

(
  • $dsn_string
)
Array static

Returns an associative array representing the dsn

Parameters:

  • $dsn_string String

    The dsn string passed to create the PDO object

Returns:

Array:

pdo

(
  • $dsn
  • $username
  • $password
  • $driver_options
)
PDO protected static

Gets the key into the associative $pdo_array corresponding to some database credentials.

Parameters:

  • $dsn String

    The dsn to create PDO

  • $username String

    Username for connection

  • $password String

    Passwork for connection

  • $driver_options Array

    Driver options

Returns:

PDO:

registerAutoloader

(
  • $class_dir=null
)
static

Registers the autoloader bundled with Db on the autoload stack. Only call this if you are running Db without Pie.

Parameters:

  • $class_dir=null String

setConnection

(
  • $name
  • $details
)
static

Add a database connection with a name

Parameters:

  • $name String

    The name under which to store the connection details

  • $details Array

    The connection details. Should include the keys: 'dsn', 'username', 'password', 'driver_options'

setShard

(
  • $conn_name
  • $shard_name
  • $modifications
)
deprecated static

Defined in platform/classes/Db.php:432

Deprecated: Shards configuration is maintained via config

Add a named shard under a database connection Can contain the keys "dsn", "username", "password", "driver_options" They are used in constructing the PDO object.

Parameters:

  • $conn_name String

    The name of the connection to which the shard pertains

  • $shard_name String

    The name under which to store the shard modifications

  • $modifications Array

    The shard modifications. Can include the keys: 'dsn', 'host', 'port', 'dbname', 'unix_socket', 'charset', 'username', 'password', 'driver_options',

setTimezones

(
  • [$offset=timezone_offset_get()]
)

If connected, sets the timezone in the database to match the one in PHP.

Parameters:

  • [$offset=timezone_offset_get()] Integer optional

    in seconds

toDate

(
  • $timestamp
)
String static

Returns a Date string to store in the database For backward compatibility. Works with MySQL and hopefully lots of other databases.

Parameters:

  • $timestamp String

    The UNIX timestamp, e.g. from strtotime function

Returns:

String:

toDateTime

(
  • $timestamp
)
String static

Returns a DateTime string to store in the database For backward compatibility. Works with MySQL and hopefully lots of other databases.

Parameters:

  • $timestamp String

    The UNIX timestamp, e.g. from strtotime function

Returns:

String:

Properties

$class_dir

String protected

Class dir cache

$connections

Array

Info about the database connections that have been added

$connections

Array

Info about the database connections that have been added

$dbs

Array

The array of Db objects that have been constructed

$pdo_array

Array protected

The array of all pdo objects that have been constructed, representing actual connections made to the databases.

Default: array()