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_name
String
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_name
StringThe name of the connection out of the connections added with Db::setConnection
Returns:
exportArray
-
$what
-
$options
Returns an array for outputting to client.
Parameters:
-
$what
MixedCould be a (multidimensional) array of Db_Row objects or a Db_Row object
-
$options
ArrayOptions 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:
-
$syntax
StringThe format of the date string, see {@link date()} function.
-
$datetime
StringThe 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:
-
$datetime
StringThe 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_name
String -
$connection_name=null
String
Returns:
getConnection
-
$name
Returns connection details for a connection
Parameters:
-
$name
String
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_name
String -
$shard_name
String
Returns:
getShards
-
$conn_name
Returns all the shards added thus far for a connection
Parameters:
-
$conn_name
String
Returns:
hash
-
$text
Hashes text in a standard way.
Parameters:
-
$text
String
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:
-
$text
StringThe 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=null
StringDefaults 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
Returns an associative array representing the dsn
Parameters:
-
$dsn_string
StringThe 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:
-
$dsn
StringThe dsn to create PDO
-
$username
StringUsername for connection
-
$password
StringPasswork for connection
-
$driver_options
ArrayDriver 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=null
String
setConnection
-
$name
-
$details
Add a database connection with a name
Parameters:
-
$name
StringThe name under which to store the connection details
-
$details
ArrayThe 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_name
StringThe name of the connection to which the shard pertains
-
$shard_name
StringThe name under which to store the shard modifications
-
$modifications
ArrayThe 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:
-
$timestamp
StringThe 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:
-
$timestamp
StringThe 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()