/**
* The required files
*/
require_once(HTML_DB_DATABASE_PATH.'/Connection.php');
/**
* The connection interface towards the DB2 database
* <code>
* Usage:
* $hostname = 'MYHOST';
* $username = 'test_user';
* $password = '********';
* $database = '20.15.22.250';
* $persistent = '';
* $portname = '10020';
* $connection = new DB2Connection($hostname,$username,$password,$database,$persistent,$portname);
* $connection->open(); // Conect to the host and select the database to use
* : // Use the connection to operate on table data
* $connection->close(); // Remember to release the connection
*
* NOTE: The username/password are defined in an external file
* </code>
* @package db2
* @todo Register function, when closing page
*/
class DB2Connection extends Connection {
/**
* Constructor
* @param String $hostname The server name to connect to
* @param String $username The username
* @param String $password The password (secret, don't look)
* @param String $database The database to use
* @param boolean $persistent Use persistent connection (true) or not (false)
* @param String $portname The server port name to connect to
*/
function DB2Connection($hostname='',$username='',$password='',$database='',$persistent='',$portname='') {
$this->Connection($hostname,$username,$password,$database,$persistent,$portname);
}
/**
* Connect to the DB2 database
* <code>
* Usage:
* $connection->open();
* </code>
* @return boolean Returns TRUE on success or FALSE if failure
*/
function open() {
$rc = false;
$conn_string = "DRIVER={IBM DB2 ODBC DRIVER};DATABASE=$this->database;HOSTNAME=$this->hostname;PORT=$this->portname;PROTOCOL=TCPIP;UID=$this->username;PWD=$this->password;";
$this->connection = db2_connect($conn_string,'','');
if (!$this->connection) {
$msg = 'DB2Connection->open() '.$this->getError();
if (defined('HTML_LOG_UTIL_PATH')) {
Log::fatal(__FILE__, __LINE__, $msg);
} else {
}
Message::add($msg,__FILE__,__LINE__);
} else {
$rc = true;
}
return $rc;
}
/**
* Close the connection to the database
* <code>
* Usage:
* $connection->close();
* </code>
* @return boolean Returns TRUE on success or FALSE on failure
*/
function close() {
$rc = false;
if ($this->connection!=NULL) {
$rc = db2_close($this->connection);
$this->connection = NULL;
} else {
$msg = 'DB2Connection->close() $this->connection is NULL';
$this->setMessage($msg);
if (defined('HTML_LOG_UTIL_PATH')) {
Log::debug(__FILE__, __LINE__, $msg);
}
Message::add($msg,__FILE__,__LINE__);
}
return $rc;
}
}
?>
HTML source code
Den fulde HTML kildekode for DB2Connection klassen
Der er ikke fundet noget
Class methods
Her er 'klasse metoderne' for DB2Connection klassen:
connection
sethostname
setusername
setpassword
setdatabase
setpersistent
setportname
open
getconnection
getdatabase
close
geterror
getmessage
setmessage
db2connection
Object vars
Her er 'objekt variable' for DB2Connection klassen: