1: <?php
2:
3: 4: 5: 6: 7: 8: 9: 10: 11: 12:
13:
14: 15: 16: 17: 18: 19: 20: 21: 22:
23: class Jyxo_Beholder_TestCase_Pgsql extends Jyxo_Beholder_TestCase
24: {
25: 26: 27: 28: 29:
30: private $query;
31:
32: 33: 34: 35: 36:
37: private $database;
38:
39: 40: 41: 42: 43:
44: private $host;
45:
46: 47: 48: 49: 50:
51: private $user;
52:
53: 54: 55: 56: 57:
58: private $password;
59:
60: 61: 62: 63: 64:
65: private $port;
66:
67: 68: 69: 70: 71:
72: private $timeout;
73:
74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 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: 101: 102: 103:
104: public function run()
105: {
106:
107: if (!extension_loaded('pgsql')) {
108: return new Jyxo_Beholder_Result(Jyxo_Beholder_Result::NOT_APPLICABLE, 'Extension pgsql missing');
109: }
110:
111:
112: $description = sprintf('%s@%s:%s/%s', $this->user, $this->host, $this->port, $this->database);
113:
114:
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:
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:
134: return new Jyxo_Beholder_Result(Jyxo_Beholder_Result::SUCCESS, $description);
135: }
136: }
137: