From 450d03aeb9741a320d5259495c33b3a121c1aa7d Mon Sep 17 00:00:00 2001 From: Dan Cryer Date: Thu, 16 May 2013 00:52:18 +0100 Subject: [PATCH] Adding PgSQL plugin, powered by PDO. Accepts connection parameters from build_settings.pgsql --- PHPCI/Plugin/Pgsql.php | 46 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 PHPCI/Plugin/Pgsql.php diff --git a/PHPCI/Plugin/Pgsql.php b/PHPCI/Plugin/Pgsql.php new file mode 100644 index 00000000..89b60170 --- /dev/null +++ b/PHPCI/Plugin/Pgsql.php @@ -0,0 +1,46 @@ +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; + } +} \ No newline at end of file