Top  Branding  Banner 
blank.gif
blank.gif
triangle.gif Du er her: /  Forsiden  /  Kildekoden  /  Db  /  Db2connection   Login nu   Login
blank.gif
««« Se kilde koden
blank.gif
tl.gif Cms tr.gif tl.gif Component tr.gif tls.gif     Db  trs.gif tl.gif Db-basket tr.gif tl.gif Db-login tr.gif tl.gif Db-customer tr.gif tl.gif Db-select tr.gif tl.gif Jquery tr.gif tl.gif Form-elements tr.gif tl.gif Menu-fisheye tr.gif tl.gif Template tr.gif tl.gif Tree-node tr.gif tl.gif Validator tr.gif
blank.gif
blank.gif
arrow-headline.gif Index
MenuLink  MenuLeft  
Tilbage

Skjul: Navn

DB2Connection.php


Vis: Sample code, tutorial

DB2Connection, Sample code, tutorial

Sådan benyttes komponenten DB2Connection klassen

Først skal du inkludere den fil der beskriver komponenten, som en klasse fil

  • <?
    require_once(HTML_PACKAGE_PATH.'/DB2Connection.php');
    ?>

Dernæst kan du enten benytte komponenten som et taglib (statiske metoder):

  • <?
    DB2Connection
    ::display($param1$param2$param3, ...);
    ?>

eller du kan lave en instance af komponenten og benytte metoderne direkte:

  • <?
    $object 
    = new DB2Connection($param1$param2$param3, ...);
    print 
    $object->getHtml();
    ?>

Skjul: Sådan vises komponenten

DB2Connection, Sådan vises komponenten

Sådan vises komponenten DB2Connection klassen


Vis: PHP source code

DB2Connection, PHP source code

Den fulde PHP kildekode for DB2Connection klassen

<?php

/**
 * @package db2
 * @see HTML_DB2_DATABASE_PATH.'/Connection.php'
 * @copyright (c) http://Finn-Rasmussen.com
 * @license http://Finn-Rasmussen.com/license/ myPHP License conditions
 * @author http://Finn-Rasmussen.com
 * @version 1.11
 * @since 27-nov-2009
 */

/**
 * 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 __construct($hostname=''$username=''$password=''$database=''$persistent=''$portname='') {
        
parent::__construct($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($msg__FILE____LINE__);
            } 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($msg__FILE____LINE__);
            }
            
Message::add($msg__FILE____LINE__);
        }
        return 
$rc;
    }
}
?>

Vis: HTML source code

DB2Connection, HTML source code

Den fulde HTML kildekode for DB2Connection klassen

<?

?>

Vis: Class methods

DB2Connection, Class methods

Her er 'klasse metoderne' for DB2Connection klassen:

  • __construct
  • open
  • close
  • setHostname
  • setUsername
  • setPassword
  • setDatabase
  • setPersistent
  • setPortname
  • getConnection
  • getDatabase
  • getError
  • getMessage
  • setMessage
  • getHtml

Vis: Object vars

DB2Connection, Object vars

Her er 'objekt variable' for DB2Connection klassen:


MenuRight 
triangle.gif

Dansk

Deutch

English (UK)

France

Italy

Norsk

Svensk

English (USA)


 
blank.gif
MenuBottom 
triangle.gif Copyright @ 1999-2010 www.Finn-Rasmussen.com Powered by myPHP Version (5.3.3-7+squeeze3) 1.11
blank.gif