Adding PgSQL plugin, powered by PDO. Accepts connection parameters from build_settings.pgsql
This commit is contained in:
parent
3ac5df9eb3
commit
450d03aeb9
46
PHPCI/Plugin/Pgsql.php
Normal file
46
PHPCI/Plugin/Pgsql.php
Normal file
|
@ -0,0 +1,46 @@
|
|||
<?php
|
||||
|
||||
namespace PHPCI\Plugin;
|
||||
use PDO;
|
||||
|
||||
class Pgsql implements \PHPCI\Plugin
|
||||
{
|
||||
protected $phpci;
|
||||
protected $queries = array();
|
||||
|
||||
protected $host;
|
||||
protected $user;
|
||||
protected $pass;
|
||||
|
||||
public function __construct(\PHPCI\Builder $phpci, array $options = array())
|
||||
{
|
||||
$this->phpci = $phpci;
|
||||
$this->queries = $options;
|
||||
|
||||
$buildSettings = $phpci->getConfig('build_settings');
|
||||
|
||||
if(isset($buildSettings['pgsql'])) {
|
||||
$sql = $buildSettings['pgsql'];
|
||||
$this->host = $sql['host'];
|
||||
$this->user = $sql['user'];
|
||||
$this->pass = $sql['pass'];
|
||||
}
|
||||
}
|
||||
|
||||
public function execute()
|
||||
{
|
||||
try {
|
||||
$pdo = new PDO('pgsql:host=' . $this->host, $this->user, $this->pass, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
|
||||
|
||||
foreach($this->queries as $query) {
|
||||
$pdo->query($query);
|
||||
}
|
||||
}
|
||||
catch(\Exception $ex) {
|
||||
$this->phpci->logFailure($ex->getMessage());
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue