DB2Database
DB2Database Du er her: /  Forsiden  /  Kildekoden  /  Db  /  Db2database   Login nu   Login
DB2Database
 ««« Se kilde koden
DB2Database
DB2Database Basic DB2Database DB2Database Base DB2Database DB2Database Component DB2Database DB2Database Db  DB2Database DB2Database Dto DB2Database DB2Database Form DB2Database DB2Database Form-elements DB2Database DB2Database Jquery DB2Database DB2Database Layout DB2Database DB2Database Menu DB2Database DB2Database Menu-fisheye DB2Database DB2Database Mvc DB2Database DB2Database Tab DB2Database DB2Database Table DB2Database DB2Database Template DB2Database DB2Database Util DB2Database
DB2Database
DB2Database
DB2Database Index
 
Tilbage

Navn : DB2Database.php


Sample code, tutorial

Sådan benyttes komponenten DB2Database klassen

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

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

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

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

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

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

Parent html

Sådan vises komponenten DB2Database klassen

ERROR, Db2database->getHtml() *** ABSTRACT *** You MUST implement this

PHP source code

Den fulde PHP kildekode for DB2Database klassen

<?
/**
* @package db2
* @see HTML_DB2_DATABASE_PATH.'/DB2Database.php'
* @copyright (c) http://Finn-Rasmussen.com
* @license http://Finn-Rasmussen.com/license/ myPHP License conditions
* @author http://Finn-Rasmussen.com
* @version 1.10
* @since 22-feb-2007
*/

/**
* The required files
*/
require_once(HTML_DB_DATABASE_PATH.'/DatabaseCommon.php');
require_once(
HTML_DB2_DATABASE_PATH.'/DB2Connection.php');
require_once(
HTML_BASIC_UTIL_PATH.'/Message.php');
if (
defined('HTML_LOG_UTIL_PATH')) {
    require_once(
HTML_LOG_UTIL_PATH.'/Log.php');
}

/**
* The interface towards the DB2 database
* The interface use an advanced sql caching methode
* <code>
* Usage:
*   $myDb = new DB2Database();
*   $myDb->open();       // Open a connection to the database
*         :
*   $myDb->doSomeThing() // Use the connection object to operate on table data
*         :
*   $myDb->close();      // Close the connection
* </code>
* @package db2
*/

class DB2Database extends DatabaseCommon {
    
/**
     * @var int $affectedRows The Number of rows affected by the drop, insert, update etc.
     */
    
var $affectedRows = 0;

    
/**
     * @var int $numRows Number of rows returned from a select,explain, etc. query
     */
    
var $numRows = 0;

    
/**
     * @var int $row The row returned
     */
    
var $row = NULL;

    
/**
     * @var String $sql The query
     */
    
var $sql = '';

    
/**
     * Constructor
     */
    
function DB2Database() {
        
$this->DatabaseCommon(CLASS_NAME_DB2_CONNECTION);
    }

    
/**
     * Execute the specified query. SELECT, UPDATE, INSERT etc...
     * Return false or a resource identifier (for SELECT,SHOW,EXPLAIN or DESCRIBE, ...)
     * @param String $sql The sql query to execute
     * @return boolean Returns TRUE (INSERT, UPDATE, DELETE, ...)
     */
    
function query($sql) {
        
$rc = false;
        if (
$this->connection!=NULL) {
            
$con = $this->connection->getConnection();
            if (
$con==NULL) {
                
$msg = $this->getClassName().'->query(), The connection is NULL. $this->connection->getConnection()';
                if (
defined('HTML_LOG_UTIL_PATH')) {
                    
Log::fatal(__FILE__,__LINE__,$msg);
                } else {
                    if (
defined('DEBUG_LEVEL') && DEBUG_LEVEL & DEBUG_LEVEL_SHOW_SQL) {
                        
Message::add($msg,__FILE__,__LINE__);
                    }
                }
                
$this->connection->close();
                return
$rc;
            }
            
$this->result = db2_exec($con, $sql, array('cursor' => DB2_SCROLLABLE));
            
$rc = $this->result!=FALSE;
            if (
$rc) {
                
/**
                 * SELECT, SHOW, DESCRIBE eller EXPLAIN returns a resource
                 * UPDATE, DELETE, DROP etc. return true on success
                 */
                
if ($this->result!==true) {
                    
$this->numRows = db2_num_rows($this->result);
                } else {
                    
//$this->affectedRows = mysql_affected_rows($con);
                
}
                
$msg = $this->getClassName()."->query(), OK, sql=".$sql." affectedRows=".$this->affectedRows;
                if (
defined('HTML_LOG_UTIL_PATH')) {
                    
Log::query(__FILE__,__LINE__,$msg);
                } else {
                    if (
defined('DEBUG_LEVEL') && DEBUG_LEVEL & DEBUG_LEVEL_SHOW_SQL) {
                        
Message::add($msg,__FILE__,__LINE__);
                    }
                }
            } else {
                
$msg = $this->getClassName().'->query(), FAILED, sql='.$sql;
                if (
defined('HTML_LOG_UTIL_PATH')) {
                    
Log::query(__FILE__,__LINE__,$msg);
                } else {
                    if (
defined('DEBUG_LEVEL') && DEBUG_LEVEL & DEBUG_LEVEL_SHOW_SQL) {
                        
Message::add($msg,__FILE__,__LINE__);
                    }
                }
                if (
defined('DEBUG_LEVEL') && DEBUG_LEVEL & DEBUG_LEVEL_SHOW_SQL) {
                    
Message::add($msg,__FILE__,__LINE__);
                }
            }
        } else {
            
$msg = $this->getClassName().'->query(), FAILED, $this->connection is NULL';
            if (
defined('HTML_LOG_UTIL_PATH')) {
                
Log::fatal(__FILE__,__LINE__,$msg);
            } else {
                if (
defined('DEBUG_LEVEL') && DEBUG_LEVEL & DEBUG_LEVEL_SHOW_SQL) {
                    
Message::add($msg,__FILE__,__LINE__);
                }
            }
        }
        return
$rc;
    }

    
/**
     * Returns the number of fields in the result   
     * @return int The number of fields in the result
     */
    
function getNumFields() {
        return
db2_num_fields($this->result);
    }
    
    
/**
     * Get the name of the specified field in a result  
     * @param  int $offset The field offset to fetch
     * @return String Returns the name of the specified field index
     */
    
function getFieldName($offset) {
        
$rc = db2_field_name($this->result,$offset);
        return
$rc===false?'':$rc;
    }

    
/**
     * Get the type of the specified field in a result   
     * @param  int $offset The field offset to fetch
     * @return String Returns the field type and will be one of
     * "int", "real", "string", "blob", ...
     */
    
function getFieldType($offset) {
        
$rc = db2_field_type($this->result,$offset);
        return
$rc===false?'':$rc;
    }

    
/**
     * Get the type of the specified field in a result
     * @todo NOT SUPPORTED   
     * @param  int $offset The field offset to fetch
     * @return String Returns the field flags
     */
    
function getFieldFlags($offset) {
        
$rc = ''; // NO SUPPORT db2_field_flags($this->result,$offset);
        
        // @todo see ../test/HelloWorld.php
        
        
return $rc===false?'':$rc;
    }

    
/**
     * Get the type of the specified field in a result
     * @todo NOT SUPPORTED   
     * @param  int $offset The field offset to fetch
     * @return String Returns the field table
     */
    
function getFieldTable($offset) {
        
$rc = ''; // NO SUPPORT db2_field_table($this->result,$offset);
        
        // @todo see ../test/HelloWorld.php
        
        
return $rc===false?'':$rc;
    }

    
/**
     * Get the length of the specified field
     * @param  int $offset The field offset to fetch
     * @return int Returns the length of the specified field
     */
    
function getFieldLen($offset) {
        
$rc = db2_field_display_size($this->result,$offset);
        return
$rc===false?'':$rc;
    }

    
/**
     * Fetch the result of the query
     * @return object Returns the contents of the resultset, returns FALSE when all have been returned
     */
    
function fetchAssoc() {
        return
db2_fetch_assoc($this->result);
    }

    
/**
     * Get the affected rows
     * @return int The number of rows affected by the query
     */
    
function getAffectedRows() {
        return
$this->affectedRows;
    }

    
/**
     * Get the number of rows
     * @return int The number of rows returned by the query
     */
    
function getNumRows() {
        return
$this->numRows;
    }
}
?>

HTML source code

Den fulde HTML kildekode for DB2Database klassen

<?
ERROR
, Db2database->getHtml() ***   ABSTRACT  ***  You MUST implement this<br />

?>

Class methods

Her er 'klasse metoderne' for DB2Database klassen:

  • db2database
  • query
  • getnumfields
  • getfieldname
  • getfieldtype
  • getfieldflags
  • getfieldtable
  • getfieldlen
  • fetchassoc
  • getaffectedrows
  • getnumrows
  • object
  • getclassname
  • getmsg
  • addhtml
  • gethtml
  • tostring
  • getcachefilename
  • save
  • content
  • stop
  • databasecommon
  • set
  • freeresult
  • geterror
  • open
  • close

Object vars

Her er 'objekt variable' for DB2Database klassen:

  • affectedRows => 0
  • numRows => 0
  • row =>
  • sql =>
  • html =>
  • connection => Object
  • result =>

DB2Database

Vis denne side på danmark

Vis denne side på Germany

Vis denne side på England

Vis denne side på France

Vis denne side på Italy

Vis denne side på Norge

Vis denne side på Sverige

Vis denne side på USA


 
DB2Database