Skip to content

Commit 9ed3e46

Browse files
committed
Created constructor for DB credentials. Left behind items in connect() which will be removed later.
1 parent 59325c5 commit 9ed3e46

File tree

1 file changed

+31
-10
lines changed

1 file changed

+31
-10
lines changed

ToolkitApi/Db2supp.php

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,24 @@ class db2supp
1212
{
1313
private $last_errorcode;
1414
private $last_errormsg;
15+
private $database;
16+
private $user;
17+
private $password;
18+
private $options;
19+
20+
/**
21+
* @param $database
22+
* @param $user
23+
* @param $password
24+
* @param null $options
25+
*/
26+
public function __construct($database, $user, $password, $options = null)
27+
{
28+
$this->database = $database;
29+
$this->user = $user;
30+
$this->password = $password;
31+
$this->options = $options;
32+
}
1533

1634
/**
1735
*
@@ -20,27 +38,28 @@ class db2supp
2038
* Throw new Exception("Fail execute ($sql) ".db2_stmt_errormsg(),db2_stmt_error());
2139
* ... and retrieve via try/catch + Exception methods.
2240
*
23-
* @param $database
24-
* @param $user
25-
* @param $password
26-
* @param null $options 'persistent' is one option
2741
* @return bool
2842
*/
2943
public function connect($database, $user, $password, $options = null)
3044
{
45+
$this->database = $database;
46+
$this->user = $user;
47+
$this->password = $password;
48+
$this->options = $options;
49+
3150
// Compensate for older ibm_db2 driver that may not do this check.
32-
if ($user && empty($password)) {
51+
if ($this->user && empty($this->password)) {
3352
$this->setErrorCode('08001');
3453
$this->setErrorMsg('Authorization failure on distributed database connection attempt. SQLCODE=-30082');
3554

3655
return false;
3756
}
3857

39-
if ($options) {
40-
if ((isset($options['persistent'])) && $options['persistent']) {
41-
$conn = db2_pconnect($database, $user, $password);
58+
if ($this->options) {
59+
if ((isset($this->options['persistent'])) && $this->options['persistent']) {
60+
$conn = db2_pconnect($this->database, $this->user, $this->password);
4261
} else {
43-
$conn = db2_connect($database, $user, $password);
62+
$conn = db2_connect($this->database, $this->user, $this->password);
4463
}
4564

4665
if (is_resource($conn)) {
@@ -67,6 +86,8 @@ public function disconnect($conn)
6786
/**
6887
* disconnect, truly close, a persistent connection.
6988
*
89+
* NOTE: Only available on i5/OS
90+
*
7091
* @param $conn
7192
*/
7293
public function disconnectPersistent($conn)
@@ -109,7 +130,7 @@ protected function setStmtError($stmt = null)
109130
} else {
110131
$this->setErrorCode(db2_stmt_error());
111132
$this->setErrorMsg(db2_stmt_errormsg());
112-
}
133+
}
113134
}
114135

115136
/**

0 commit comments

Comments
 (0)