Overview

Packages

  • Jyxo_Beholder
  • Jyxo_Charset
  • Jyxo_Color
  • Jyxo_Css
  • Jyxo_ErrorHandling
  • Jyxo_FirePhp
  • Jyxo_Gettext
    • Parser
  • Jyxo_Html
  • Jyxo_Input
    • Chain
    • Filter
    • Validator
  • Jyxo_Mail
    • Email
    • Parser
    • Sender
  • Jyxo_Rpc
    • Json
    • Xml
  • Jyxo_Shell
  • Jyxo_SpamFilter
  • Jyxo_Spl
  • Jyxo_String
  • Jyxo_Svn
  • Jyxo_Time
  • Jyxo_Timer
  • Jyxo_Webdav
  • Jyxo_XmlReader
  • PHP

Classes

  • Jyxo_Beholder_Executor
  • Jyxo_Beholder_Result
  • Jyxo_Beholder_TestCase
  • Jyxo_Beholder_TestCase_FileSystem
  • Jyxo_Beholder_TestCase_HttpResponse
  • Jyxo_Beholder_TestCase_Imap
  • Jyxo_Beholder_TestCase_JsonRpc
  • Jyxo_Beholder_TestCase_Memcached
  • Jyxo_Beholder_TestCase_Mysql
  • Jyxo_Beholder_TestCase_Pgsql
  • Jyxo_Beholder_TestCase_PhpExtension
  • Jyxo_Beholder_TestCase_PhpVersion
  • Jyxo_Beholder_TestCase_PhpZend
  • Jyxo_Beholder_TestCase_Smtp
  • Jyxo_Beholder_TestCase_Webdav
  • Jyxo_Beholder_TestCase_XmlRpc
  • Overview
  • Package
  • 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: /**
 15:  * Tests PostgreSQL availability.
 16:  *
 17:  * @category Jyxo
 18:  * @package Jyxo_Beholder
 19:  * @copyright Copyright (c) 2005-2011 Jyxo, s.r.o.
 20:  * @license https://github.com/jyxo/php/blob/master/license.txt
 21:  * @author Jaroslav HanslĂ­k
 22:  */
 23: class Jyxo_Beholder_TestCase_Pgsql extends Jyxo_Beholder_TestCase
 24: {
 25:     /**
 26:      * SQL query.
 27:      *
 28:      * @var string
 29:      */
 30:     private $query;
 31: 
 32:     /**
 33:      * Database name.
 34:      *
 35:      * @var string
 36:      */
 37:     private $database;
 38: 
 39:     /**
 40:      * Hostname.
 41:      *
 42:      * @var string
 43:      */
 44:     private $host;
 45: 
 46:     /**
 47:      * Username.
 48:      *
 49:      * @var string
 50:      */
 51:     private $user;
 52: 
 53:     /**
 54:      * Password.
 55:      *
 56:      * @var string
 57:      */
 58:     private $password;
 59: 
 60:     /**
 61:      * Port.
 62:      *
 63:      * @var integer
 64:      */
 65:     private $port;
 66: 
 67:     /**
 68:      * Timeout.
 69:      *
 70:      * @var integer
 71:      */
 72:     private $timeout;
 73: 
 74:     /**
 75:      * Constructor.
 76:      *
 77:      * @param string $description Test description
 78:      * @param string $query Tested query
 79:      * @param string $database Database name
 80:      * @param string $host Hostname
 81:      * @param string $user Username
 82:      * @param string $password Password
 83:      * @param integer $port Port
 84:      * @param integer $timeout Timeout
 85:      */
 86:     public function __construct($description, $query, $database, $host = 'localhost', $user = '', $password = '', $port = 5432, $timeout = 2)
 87:     {
 88:         parent::__construct($description);
 89: 
 90:         $this->query = (string) $query;
 91:         $this->database = (string) $database;
 92:         $this->host = (string) $host;
 93:         $this->user = (string) $user;
 94:         $this->password = (string) $password;
 95:         $this->port = (int) $port;
 96:         $this->timeout = (int) $timeout;
 97:     }
 98: 
 99:     /**
100:      * Performs the test.
101:      *
102:      * @return Jyxo_Beholder_Result
103:      */
104:     public function run()
105:     {
106:         // The pgsql extension is required
107:         if (!extension_loaded('pgsql')) {
108:             return new Jyxo_Beholder_Result(Jyxo_Beholder_Result::NOT_APPLICABLE, 'Extension pgsql missing');
109:         }
110: 
111:         // Status label
112:         $description = sprintf('%s@%s:%s/%s', $this->user, $this->host, $this->port, $this->database);
113: 
114:         // Connection
115:         $db = pg_connect(sprintf(
116:             'host=%s port=%d dbname=%s user=%s password=%s connect_timeout=%d',
117:             $this->host, $this->port, $this->database, $this->user, $this->password, $this->timeout
118:         ));
119:         if (false === $db) {
120:             return new Jyxo_Beholder_Result(Jyxo_Beholder_Result::FAILURE, sprintf('Connection error %s', $description));
121:         }
122: 
123:         // Query (the leading space is because of pgpool)
124:         $result = pg_query($db, ' ' . $this->query);
125:         if (false === $result) {
126:             pg_close($db);
127:             return new Jyxo_Beholder_Result(Jyxo_Beholder_Result::FAILURE, sprintf('Query error %s', $description));
128:         }
129: 
130:         pg_free_result($result);
131:         pg_close($db);
132: 
133:         // OK
134:         return new Jyxo_Beholder_Result(Jyxo_Beholder_Result::SUCCESS, $description);
135:     }
136: }
137: 
Jyxo PHP Library API documentation generated by ApiGen 2.3.0