Class \Scrivo\PdoConnection
Class to manage the connection to the Scrivo database.
This is simply a direct descendent of the \PDO class with a modified constructor that uses a Scrivo configuration object to open the connection. It also assures that the connection is configured correctly (uses exceptions and UTF-8).
It is possible to store data of several instances (sites) in a single database. The instance data is identified by an instance id which is also defined in the configuration file and present a property of this class.
Furthermore, Scrivo uses object ids instead of auto-numbering. Ids within a specific instance need to be unique. To achieve this this class also deals with the generation of unique ids.
Extends
\PDO .
Defined in:
PdoConnection.php.
Attr. | Name / Description |
---|---|
public |
PdoConnection($config) Construct a scrivo database connection using the setting in a Scrivo config file. |
Attr. | Type | Name | Description |
---|---|---|---|
private | int | $instId | The database instance id. |
Attr. | Type | Name / Description |
---|---|---|
public | mixed |
__get($field) Implementation of the readable properties using the PHP magic method __get(). |
public |
bindInstance($sth, $label) Convenience method for setting the instance variable in an prepared statment. |
|
public | int |
Generate a new object id. |
public | int |
Get the database instance id. |
public | PDOStatement |
prepare($statement, $options) Overloaded version of PDO::prepare, just to be able to do some query logging. |
Constructor
- public PdoConnection(\Scrivo\Config $config)
-
Construct a scrivo database connection using the setting in a Scrivo config file.
The following settings are used:
- DB_HOST
- DB_NAME
- DB_USER
- DB_PASSWORD
- INSTANCE_ID
Parameters:
Type Name Def. Description \Scrivo\Config $config A Scrivo config object that contains the database settings.
View source: PdoConnection.php line 77.
Members
- private int $instId
-
The database instance id.
View source: PdoConnection.php line 62.
Methods
- public mixed __get(string $field)
-
Implementation of the readable properties using the PHP magic method __get().
Parameters:
Type Name Def. Description string $field The name of the property to get.
Returns:
mixed Implementation of the readable properties using the PHP magic method __get().
View source: PdoConnection.php line 148.
- public bindInstance(\PDOStatement $sth, string $label=":instId")
-
Convenience method for setting the instance variable in an prepared statment.
This variable is usually named ":instId", but you can use an alternative name.
Parameters:
Type Name Def. Description \PDOStatement $sth The statement for which to set the instance id.
string $label ":instId" An optional alternative label for the instance id variable.
View source: PdoConnection.php line 136.
- public int generateId()
-
Generate a new object id.
For the generation of an object id in MySQL we use a table with one autoincrement column.
TODO: setup a test to see how this holds in concurrency situations and document it (the behavoir not the test).
Returns:
int Generate a new object id.
View source: PdoConnection.php line 111.
- public int getInstanceId()
-
Get the database instance id.
Returns:
int Get the database instance id.
View source: PdoConnection.php line 96.
- public \PDOStatement prepare(string $statement, array $options=array())
-
Overloaded version of PDO::prepare, just to be able to do some query logging.
Parameters:
Type Name Def. Description string $statement An SQL statement.
array $options array() Driver options.
Returns:
\PDOStatement Overloaded version of PDO::prepare, just to be able to do some query logging.
View source: PdoConnection.php line 165.
Documentation generated by phpDocumentor 2.0.0a12 and ScrivoDocumentor on August 29, 2013