Download the PHP package liquidbox/silex-pdo without Composer
On this page you can find all versions of the php package liquidbox/silex-pdo. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package silex-pdo
You are reading the documentation for Silex 2.x. Switch to the documentation for Silex 1.x.
PHP Data Objects
The PdoServiceProvider provides integration with the PHP Data Objects (PDO) extension.
Parameters
- pdo.dsn (optional): The Data Source Name, or DSN, contains the information required to connect to the database.
- pdo.driver (optional): The PDO driver implementation to use.
- pdo.connection (optional): A collection of driver-specific connection parameters for specifying the connection string.
- pdo.username (optional): The user name for the DSN string.
- pdo.password (optional): The password for the DSN string.
- pdo.options (optional): A collection of driver-specific connection options.
- pdo.attributes (optional): A collection of attributes to set.
The parameters pdo.driver
and pdo.connection
are ignored if pdo.dsn
is set.
Services
- pdo: The
PDO
connection instance. The main way of interacting with PDO. - pdo.connections: The collection of PDO connection instances. See section on using multiple databases for details.
- pdo.connect: Factory for
PDO
connection instances.
Registering
Example #1 Connecting to MySQL
The two registered connections are equivalent.
Example #2 Connecting to SQLite
Example #3 Using Doctrine service names
The services pdo
and pdo.connections
will be renamed db
and dbs
respectively.
Add PDO as a dependency:
Usage
Example #1 Demonstrate query
Example #2 Prepare an SQL statement with named parameters
Using multiple databases
The PDO provider can allow access to multiple databases. In order to configure the data sources, use pdo.dsn as an array of configurations where keys are connection names and values are parameters:
The first registered connection is the default and can simply be accessed as you would if there was only one connection. Given the above configuration, these two lines are equivalent:
You can use different drivers for each connection.
This registers $app['pdo.dbs']['member_db']
, $app['pdo.dbs']['content_db']
, and $app['pdo.dbs']['session_storage']
using PostgreSQL, MySQL, and SQLite drivers respectively.
Traits
LiquidBox\Silex\Application\PdoTrait
adds the following shortcut:
- prepare: Prepares a statement for execution and returns a statement object.
For more information, check out the official PDO documentation.