PHPackages                             lts/microdeps-pdo - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. lts/microdeps-pdo

ActiveLibrary[Database &amp; ORM](/categories/database)

lts/microdeps-pdo
=================

A micro dependency that provides a PDO connection factory

026PHP

Since Nov 15Pushed 4y agoCompare

[ Source](https://github.com/LongTermSupport/microdeps-pdo)[ Packagist](https://packagist.org/packages/lts/microdeps-pdo)[ RSS](/packages/lts-microdeps-pdo/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

MicroDeps/PDO
=============

[](#microdepspdo)

MicroDeps are all about very small pieces of code that do a single small thing well

This MicroDep is for PDO

Simply enough it provides a factory for creating PDO instances

Currently this supports MySQL and SQLite Databases, more can be added easily enough, pull requests gratefully received!

Installing
----------

[](#installing)

You can use Composer if you want to quickly test out the idea, though it is suggested that as this is so small - you might be better just copy/pasting it into your first party code.

```
composer require lts/microdeps-pdo

```

Configuration
-------------

[](#configuration)

You have the choice of defining configuration values as constants using `define`, or you can add these to the `$_ENV` super global, perhaps using something like

Constants are discouraged but catered for should you wish to use them.

You can also pass in configuration manually at run time, though this is really only intended for testing purposes.

You can see all the possible configuration keys defined in [./src/Config.php](./src/Config.php)

The specific keys you need to define will depend on the database type you want to use, for example:

### MySQL

[](#mysql)

```
DB_SERVER_USERNAME="foo"
DB_SERVER_PASSWORD="foo"
DB_DATABASE="foo"

```

### SQLite

[](#sqlite)

```
DB_TYPE=sqlite
DB_SQLITE_PATH=/path/to/file

```

Usage
-----

[](#usage)

Assuming you have defined the correct configuration then creating a PDO instance looks like this:

```
