2017 © Pedro Peláez
 

library dsnfromenv

image

enru/dsnfromenv

  • Tuesday, February 12, 2013
  • by enru
  • Repository
  • 1 Watchers
  • 1 Stars
  • 71 Installations
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

dsnfromenv

Parses a database URL from the environment into a DSN connection string for use in PHP's PDO., (*1)

Useful for parsing heroku config DATABASE_URL variable., (*2)

e.g., (*3)

A database URL set in an environment variable:, (*4)

export DATABASE_URL=postgres://USER:PASS@HOST:PORT/DBNAME

...can be parsed into this string:, (*5)

'pgsql:host=HOST;port=PORT;user=USER;dbname=DBNAME;password=PASSWORD'

...using this code:, (*6)

<?php

$dsn = new enru\DsnFromEnv();
$dsn_string = $dsn->parse();

A database connection can then easily be made:, (*7)

<?php

try {
    $dsn = new enru\DsnFromEnv();
    $dbh = new PDO($dsn->parse());
}   
catch (PDOException $e) {
    print "Error!: " . $e->getMessage() . "<br/>";
    die();
} 

The Versions

12/02 2013

dev-master

9999999-dev

  Sources   Download

The Requires

  • php >=5.3.0

 

12/02 2013

v1.0.1

1.0.1.0

  Sources   Download

The Requires

  • php >=5.3.0

 

12/02 2013

v1.0

1.0.0.0

  Sources   Download

The Requires

  • php >=5.3.0