Overview

Namespaces

  • Jyxo
    • Beholder
      • TestCase
    • Gettext
      • Parser
    • Input
      • Chain
      • Filter
      • Validator
    • Mail
      • Email
        • Attachment
      • Parser
      • Sender
    • Rpc
      • Json
      • Xml
    • Shell
    • Spl
    • Svn
    • Time
    • Webdav
  • PHP

Classes

  • FileSystem
  • HttpResponse
  • Imap
  • JsonRpc
  • Memcached
  • Mysql
  • Pgsql
  • PhpExtension
  • PhpVersion
  • PhpZend
  • Smtp
  • Webdav
  • XmlRpc
  • Overview
  • Namespace
  • Class
  • Tree
  • Deprecated
  1: <?php
  2: 
  3: /**
  4:  * Jyxo PHP Library
  5:  *
  6:  * LICENSE
  7:  *
  8:  * This source file is subject to the new BSD license that is bundled
  9:  * with this package in the file license.txt.
 10:  * It is also available through the world-wide-web at this URL:
 11:  * https://github.com/jyxo/php/blob/master/license.txt
 12:  */
 13: 
 14: namespace Jyxo\Beholder\TestCase;
 15: 
 16: /**
 17:  * Tests PostgreSQL availability.
 18:  *
 19:  * @category Jyxo
 20:  * @package Jyxo\Beholder
 21:  * @copyright Copyright (c) 2005-2011 Jyxo, s.r.o.
 22:  * @license https://github.com/jyxo/php/blob/master/license.txt
 23:  * @author Jaroslav HanslĂ­k
 24:  */
 25: class Pgsql extends \Jyxo\Beholder\TestCase
 26: {
 27:     /**
 28:      * SQL query.
 29:      *
 30:      * @var string
 31:      */
 32:     private $query;
 33: 
 34:     /**
 35:      * Database name.
 36:      *
 37:      * @var string
 38:      */
 39:     private $database;
 40: 
 41:     /**
 42:      * Hostname.
 43:      *
 44:      * @var string
 45:      */
 46:     private $host;
 47: 
 48:     /**
 49:      * Username.
 50:      *
 51:      * @var string
 52:      */
 53:     private $user;
 54: 
 55:     /**
 56:      * Password.
 57:      *
 58:      * @var string
 59:      */
 60:     private $password;
 61: 
 62:     /**
 63:      * Port.
 64:      *
 65:      * @var integer
 66:      */
 67:     private $port;
 68: 
 69:     /**
 70:      * Timeout.
 71:      *
 72:      * @var integer
 73:      */
 74:     private $timeout;
 75: 
 76:     /**
 77:      * Constructor.
 78:      *
 79:      * @param string $description Test description
 80:      * @param string $query Tested query
 81:      * @param string $database Database name
 82:      * @param string $host Hostname
 83:      * @param string $user Username
 84:      * @param string $password Password
 85:      * @param integer $port Port
 86:      * @param integer $timeout Timeout
 87:      */
 88:     public function __construct($description, $query, $database, $host = 'localhost', $user = '', $password = '', $port = 5432, $timeout = 2)
 89:     {
 90:         parent::__construct($description);
 91: 
 92:         $this->query = (string) $query;
 93:         $this->database = (string) $database;
 94:         $this->host = (string) $host;
 95:         $this->user = (string) $user;
 96:         $this->password = (string) $password;
 97:         $this->port = (int) $port;
 98:         $this->timeout = (int) $timeout;
 99:     }
100: 
101:     /**
102:      * Performs the test.
103:      *
104:      * @return \Jyxo\Beholder\Result
105:      */
106:     public function run()
107:     {
108:         // The pgsql extension is required
109:         if (!extension_loaded('pgsql')) {
110:             return new \Jyxo\Beholder\Result(\Jyxo\Beholder\Result::NOT_APPLICABLE, 'Extension pgsql missing');
111:         }
112: 
113:         // Status label
114:         $description = sprintf('%s@%s:%s/%s', $this->user, $this->host, $this->port, $this->database);
115: 
116:         // Connection
117:         $db = pg_connect(sprintf(
118:             'host=%s port=%d dbname=%s user=%s password=%s connect_timeout=%d',
119:             $this->host, $this->port, $this->database, $this->user, $this->password, $this->timeout
120:         ));
121:         if (false === $db) {
122:             return new \Jyxo\Beholder\Result(\Jyxo\Beholder\Result::FAILURE, sprintf('Connection error %s', $description));
123:         }
124: 
125:         // Query (the leading space is because of pgpool)
126:         $result = pg_query($db, ' ' . $this->query);
127:         if (false === $result) {
128:             pg_close($db);
129:             return new \Jyxo\Beholder\Result(\Jyxo\Beholder\Result::FAILURE, sprintf('Query error %s', $description));
130:         }
131: 
132:         pg_free_result($result);
133:         pg_close($db);
134: 
135:         // OK
136:         return new \Jyxo\Beholder\Result(\Jyxo\Beholder\Result::SUCCESS, $description);
137:     }
138: }
139: 
Jyxo PHP Library API documentation generated by ApiGen 2.3.0