Api Documentation Version 0.9.2
The database connection manager is an excelent tool that can help you to manage database connections for your application / website.
This component will store the connection details and conveniently initialize a pdo object to handle queries.
This tool offers also full support for the PtcQueryBuilder component, if specified as an option when adding a connection.
To start managing your database connections with the component, we can use the PtcDb::add( ) method to add a connection:
We just added a new connection to the connection manager.
"$name"is not specified, the class will automatically use the default connection.
The following sections will describe these options in details:
This option sets the connection name.
"$name"argument to the PtcDb::add( ) method directly.
This is the driver that the pdo object will use, currently only mysql is supported.
This option sets the database username.
This option sets the username password.
This option sets the databse host.
This option sets the database name.
This option sets the charset for the database connection.
This option adds query builder support to the connection manager, keep in mind that the PtcQueryBuilder component needs to be present.
See Using the Query Builder for a detailed explanation on using the Query Builder.
This option sets the name of the query builder component, usefull if the component has been extended or is under a namespace.
This option sets attributes to the pdo object.
These are the default attributes that are been set when the PtcDb::add( ) method is called:
To use the Pdo object to handle queries with the default connection is very simple, here is and example that speaks for it self:
To use another connection you can use the PtcDb::getPdo( ) method:
To start using the PtcQueryBuilder component with the database connection manager we need to specify it when we are adding a connection.
Here is a practical example:
To call methods from the PtcQueryBuilder is just like using the Pdo, here is an example using the default connection:
To retrieve the query builder object from another connection, the method PtcDb::getQB( ) can be used:
Refer to the Query Builder Component (PtcQueryBuilder) user manual for detailed usage.
$nameis not specified, all configured connections will be returned.