Db Class
Abstract class for database connection
Item Index
Methods
- autoload static
- connect static
- exportArray static
- fromDate static
- fromDateTime static
- generateTableClassName static
- getConnection static
- getConnections static
- getShard static
- getShards static deprecated
- hash static
- normalize static
- parseDsnString static
- pdo static
- registerAutoloader static
- setConnection static
- setShard static deprecated
- setTimezones
- toDate static
- toDateTime static
Properties
Methods
autoload
-
$class_name
If Db is used a standalone library, then this autoloader will be used after you call Db::registerAutoload()
Parameters:
-
$class_nameString
connect
-
$conn_name
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_nameStringThe name of the connection out of the connections added with Db::setConnection
Returns:
exportArray
-
$what -
$options
Returns an array for outputting to client.
Parameters:
-
$whatMixedCould be a (multidimensional) array of Db_Row objects or a Db_Row object
-
$optionsArrayOptions for row exportArray methods. Can also include the following:
-
[numeric]Boolean optionalMakes a plain numerically indexed array, even if $what has keys
-
Returns:
fromDate
-
$syntax -
$datetime
Returns a timestamp from a Date string For backward compatibility. Works with MySQL and hopefully lots of other databases.
Parameters:
-
$syntaxStringThe format of the date string, see {@link date()} function.
-
$datetimeStringThe DateTime string that comes from the db
Returns:
The timestamp
fromDateTime
-
$datetime
Returns a timestamp from a DateTime string For backward compatibility. Works with MySQL and hopefully lots of other databases.
Parameters:
-
$datetimeStringThe DateTime string that comes from the db
Returns:
The timestamp
generateTableClassName
-
$table_name -
$connection_name=null
Generates a class name given a table name
Parameters:
-
$table_nameString -
$connection_name=nullString
Returns:
getConnection
-
$name
Returns connection details for a connection
Parameters:
-
$nameString
Returns:
getConnections
()
Array
static
Returns all the connections added thus far
Returns:
getShard
-
$conn_name -
$shard_name
Returns modification details for a shard pertaining to a connection
Parameters:
-
$conn_nameString -
$shard_nameString
Returns:
getShards
-
$conn_name
Returns all the shards added thus far for a connection
Parameters:
-
$conn_nameString
Returns:
hash
-
$text
Hashes text in a standard way.
Parameters:
-
$textString
Returns:
The hash string
normalize
-
$text -
$replacement='_' -
$characters=null -
$numChars=233
Normalizes text by converting it to lower case, and replacing all non-accepted characters with underscores.
Parameters:
-
$textStringThe text to normalize
-
$replacement='_'StringDefaults to '_'. A string to replace one or more unacceptable characters. You can also change this default using the config Db/normalize/replacement
-
$characters=nullStringDefaults 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=233Integer
parseDsnString
-
$dsn_string
Returns an associative array representing the dsn
Parameters:
-
$dsn_stringStringThe dsn string passed to create the PDO object
Returns:
pdo
-
$dsn -
$username -
$password -
$driver_options
Gets the key into the associative $pdo_array corresponding to some database credentials.
Parameters:
-
$dsnStringThe dsn to create PDO
-
$usernameStringUsername for connection
-
$passwordStringPasswork for connection
-
$driver_optionsArrayDriver options
Returns:
registerAutoloader
-
$class_dir=null
Registers the autoloader bundled with Db on the autoload stack. Only call this if you are running Db without Pie.
Parameters:
-
$class_dir=nullString
setConnection
-
$name -
$details
Add a database connection with a name
Parameters:
-
$nameStringThe name under which to store the connection details
-
$detailsArrayThe connection details. Should include the keys: 'dsn', 'username', 'password', 'driver_options'
setShard
-
$conn_name -
$shard_name -
$modifications
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_nameStringThe name of the connection to which the shard pertains
-
$shard_nameStringThe name under which to store the shard modifications
-
$modificationsArrayThe 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 optionalin seconds
toDate
-
$timestamp
Returns a Date string to store in the database For backward compatibility. Works with MySQL and hopefully lots of other databases.
Parameters:
-
$timestampStringThe UNIX timestamp, e.g. from strtotime function
Returns:
toDateTime
-
$timestamp
Returns a DateTime string to store in the database For backward compatibility. Works with MySQL and hopefully lots of other databases.
Parameters:
-
$timestampStringThe UNIX timestamp, e.g. from strtotime function
Returns:
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()