IBM DB2 é–ąæ•°

ç›źæŹĄ

  • db2_autocommit — ăƒ‡ăƒŒă‚żăƒ™ăƒŒă‚čæŽ„続た AUTOCOMMIT ăźçŠ¶æ…‹ă‚’ć–ćŸ—ăŸăŸăŻèš­ćźšă™ă‚‹
  • db2_bind_param — PHP ć€‰æ•°ă‚’ SQL æ–‡ăźăƒ‘ăƒ©ăƒĄăƒŒă‚żă«ăƒă‚€ăƒłăƒ‰ă™ă‚‹
  • db2_client_info — DB2 ăƒ‡ăƒŒă‚żăƒ™ăƒŒă‚čă‚Żăƒ©ă‚€ă‚ąăƒłăƒˆăźæƒ…ć ±ă‚’ăƒ—ăƒ­ăƒ‘ăƒ†ă‚Łă«äżæŒă™ă‚‹ă‚Șăƒ–ă‚žă‚§ă‚Żăƒˆă‚’èż”ă™
  • db2_close — ăƒ‡ăƒŒă‚żăƒ™ăƒŒă‚čæŽ„ç¶šă‚’é–‰ă˜ă‚‹
  • db2_column_privileges — ăƒ†ăƒŒăƒ–ăƒ«ăźă‚«ăƒ©ăƒ ăŠă‚ˆăłé–ąé€Łă™ă‚‹æš©é™æƒ…ć ±ă‚’ć«ă‚€ç”æžœă‚»ăƒƒăƒˆă‚’èż”ă™
  • db2_columns — ăƒ†ăƒŒăƒ–ăƒ«ăźă‚«ăƒ©ăƒ ăŠă‚ˆăłé–ąé€Łă™ă‚‹ăƒĄă‚żăƒ‡ăƒŒă‚żă‚’ć«ă‚€ç”æžœă‚»ăƒƒăƒˆă‚’èż”ă™
  • db2_commit — ăƒˆăƒ©ăƒłă‚¶ă‚Żă‚·ăƒ§ăƒłă‚’ă‚łăƒŸăƒƒăƒˆă™ă‚‹
  • db2_conn_error — ç›Žèż‘ăźæŽ„ç¶šă‹ă‚‰èż”ă•ă‚ŒăŸ SQLSTATE ă‚’ć«ă‚€æ–‡ć­—ćˆ—ă‚’èż”ă™
  • db2_conn_errormsg — ç›Žèż‘ăźæŽ„ç¶šă‚šăƒ©ăƒŒăƒĄăƒƒă‚»ăƒŒă‚žăŠă‚ˆăł SQLCODE ă‚’èż”ă™
  • db2_connect — ăƒ‡ăƒŒă‚żăƒ™ăƒŒă‚čăžăźæŽ„ç¶šă‚’èż”ă™
  • db2_cursor_type — ă‚čăƒ†ăƒŒăƒˆăƒĄăƒłăƒˆăƒȘă‚œăƒŒă‚čăŒäœżç”šă—ăŠă„ă‚‹ă‚«ăƒŒă‚œăƒ«ăźćž‹ă‚’èż”ă™
  • db2_escape_string — ç‰čćźšăźæ–‡ć­—ă‚’ă‚šă‚čă‚±ăƒŒăƒ—ă™ă‚‹
  • db2_exec — SQL æ–‡ă‚’ç›ŽæŽ„ćźŸèĄŒă™ă‚‹
  • db2_execute — プăƒȘペケドă‚čăƒ†ăƒŒăƒˆăƒĄăƒłăƒˆă‚’ćźŸèĄŒă™ă‚‹
  • db2_fetch_array — ç”æžœă‚»ăƒƒăƒˆć†…ăźèĄŒă‚’èĄšă™ă€ă‚«ăƒ©ăƒ äœçœźă‚’ă‚€ăƒłăƒ‡ăƒƒă‚Żă‚čăšă™ă‚‹é…ćˆ—ă‚’èż”ă™
  • db2_fetch_assoc — ç”æžœă‚»ăƒƒăƒˆć†…ăźèĄŒă‚’èĄšă™ă€ă‚«ăƒ©ăƒ ćă‚’ă‚€ăƒłăƒ‡ăƒƒă‚Żă‚čăšă™ă‚‹é…ćˆ—ă‚’èż”ă™
  • db2_fetch_both — ç”æžœă‚»ăƒƒăƒˆć†…ăźèĄŒă‚’èĄšă™ă€ ă‚«ăƒ©ăƒ äœçœźăŠă‚ˆăłă‚«ăƒ©ăƒ ćăźäžĄæ–čă‚’ă‚€ăƒłăƒ‡ăƒƒă‚Żă‚čăšă™ă‚‹é…ćˆ—ă‚’èż”ă™
  • db2_fetch_object — ç”æžœă‚»ăƒƒăƒˆć†…ăźèĄŒă‚’èĄšă™ă€ă‚«ăƒ©ăƒ ă‚’ăƒ—ăƒ­ăƒ‘ăƒ†ă‚Łăšă™ă‚‹ă‚Șăƒ–ă‚žă‚§ă‚Żăƒˆă‚’èż”ă™
  • db2_fetch_row — ç”æžœă‚»ăƒƒăƒˆăƒă‚€ăƒłă‚żă‚’æŹĄăźèĄŒă‚ă‚‹ă„ăŻèŠæ±‚ă•ă‚ŒăŸèĄŒă«èš­ćźšă™ă‚‹
  • db2_field_display_size — ă‚«ăƒ©ăƒ ă‚’èĄšç€șă™ă‚‹ăŸă‚ă«ćż…èŠăȘæœ€ć€§ăźăƒă‚€ăƒˆæ•°ă‚’èż”ă™
  • db2_field_name — ç”æžœă‚»ăƒƒăƒˆć†…ăźă‚«ăƒ©ăƒ ăźćć‰ă‚’èż”ă™
  • db2_field_num — ç”æžœă‚»ăƒƒăƒˆć†…ăźæŒ‡ćźšă—ăŸă‚«ăƒ©ăƒ ăźäœçœźă‚’èż”ă™
  • db2_field_precision — ç”æžœă‚»ăƒƒăƒˆć†…ăźæŒ‡ćźšă—ăŸă‚«ăƒ©ăƒ ăźçČŸćșŠă‚’èż”ă™
  • db2_field_scale — ç”æžœă‚»ăƒƒăƒˆć†…ăźæŒ‡ćźšă—ăŸă‚«ăƒ©ăƒ ăźäœć–ă‚Šă‚’èż”ă™
  • db2_field_type — ç”æžœă‚»ăƒƒăƒˆć†…ăźæŒ‡ćźšă—ăŸă‚«ăƒ©ăƒ ăźăƒ‡ăƒŒă‚żćž‹ă‚’èż”ă™
  • db2_field_width — ç”æžœă‚»ăƒƒăƒˆć†…ăźæŒ‡ćźšă—ăŸă‚«ăƒ©ăƒ ăźçŸćœšć€€ăźćč…ă‚’èż”ă™
  • db2_foreign_keys — ăƒ†ăƒŒăƒ–ăƒ«ăźć€–éƒšă‚­ăƒŒă‚’ć«ă‚€ç”æžœă‚»ăƒƒăƒˆă‚’èż”ă™
  • db2_free_result — ç”æžœă‚»ăƒƒăƒˆă«é–ąé€Łä»˜ă‘ă‚‰ă‚ŒăŸăƒȘă‚œăƒŒă‚čă‚’é–‹æ”Ÿă™ă‚‹
  • db2_free_stmt — æŒ‡ćźšă•ă‚ŒăŸă‚čăƒ†ăƒŒăƒˆăƒĄăƒłăƒˆăƒȘă‚œăƒŒă‚čă«é–ąé€Łä»˜ă‘ă‚‰ă‚ŒăŸăƒȘă‚œăƒŒă‚čă‚’é–‹æ”Ÿă™ă‚‹
  • db2_get_option — ă‚čăƒ†ăƒŒăƒˆăƒĄăƒłăƒˆăƒȘă‚œăƒŒă‚čă‚ă‚‹ă„ăŻæŽ„ç¶šăƒȘă‚œăƒŒă‚čからă‚Șăƒ—ă‚·ăƒ§ăƒłăźć€€ă‚’ć–ćŸ—ă™ă‚‹
  • db2_last_insert_id — ă“ăźæŽ„ç¶šäžŠă§æœ€ćŸŒă«æˆćŠŸă—ăŸ insert クスăƒȘがè‡Șć‹•ç”Ÿæˆă—ăŸ ID ă‚’èż”ă™
  • db2_lob_read — LOB ăƒ•ă‚Ąă‚€ăƒ«ă‹ă‚‰ă€ăƒŠăƒŒă‚¶ăƒŒăŒćźšçŸ©ă—ăŸă‚”ă‚€ă‚șぼ憅ćźčă‚’ć–ćŸ—ă™ă‚‹
  • db2_next_result — ă‚čăƒˆă‚ąăƒ‰ăƒ—ăƒ­ă‚·ăƒŒă‚žăƒŁă‹ă‚‰ă€æŹĄăźç”æžœă‚»ăƒƒăƒˆă‚’èŠæ±‚ă™ă‚‹
  • db2_num_fields — ç”æžœă‚»ăƒƒăƒˆă«ć«ăŸă‚Œă‚‹ăƒ•ă‚ŁăƒŒăƒ«ăƒ‰ăźæ•°ă‚’èż”ă™
  • db2_num_rows — SQL æ–‡ă«ă‚ˆăŁăŠć€‰æ›Žă•ă‚ŒăŸèĄŒăźæ•°ă‚’èż”ă™
  • db2_pclose — æŒç¶šçš„ăƒ‡ăƒŒă‚żăƒ™ăƒŒă‚čæŽ„ç¶šă‚’é–‰ă˜ă‚‹
  • db2_pconnect — ăƒ‡ăƒŒă‚żăƒ™ăƒŒă‚čăžăźæŒç¶šçš„æŽ„ç¶šă‚’èż”ă™
  • db2_prepare — ćźŸèĄŒă™ă‚‹ SQL æ–‡ă‚’æș–悙する
  • db2_primary_keys — ăƒ†ăƒŒăƒ–ăƒ«ăźäž»ă‚­ăƒŒă‚’ć«ă‚€ç”æžœă‚»ăƒƒăƒˆă‚’èż”ă™
  • db2_procedure_columns — ă‚čăƒˆă‚ąăƒ‰ăƒ—ăƒ­ă‚·ăƒŒă‚žăƒŁăźăƒ‘ăƒ©ăƒĄăƒŒă‚żă‚’ć«ă‚€ç”æžœă‚»ăƒƒăƒˆă‚’èż”ă™
  • db2_procedures — ăƒ‡ăƒŒă‚żăƒ™ăƒŒă‚č憅に登éŒČされどいるă‚čăƒˆă‚ąăƒ‰ăƒ—ăƒ­ă‚·ăƒŒă‚žăƒŁăźäž€èŠ§ă‚’ć«ă‚€ç”æžœă‚»ăƒƒăƒˆă‚’èż”ă™
  • db2_result — ç”æžœă‚»ăƒƒăƒˆăźèĄŒă‹ă‚‰ăČăšă€ăźă‚«ăƒ©ăƒ ă‚’èż”ă™
  • db2_rollback — ăƒˆăƒ©ăƒłă‚¶ă‚Żă‚·ăƒ§ăƒłă‚’ăƒ­ăƒŒăƒ«ăƒăƒƒă‚Żă™ă‚‹
  • db2_server_info — DB2 ăƒ‡ăƒŒă‚żăƒ™ăƒŒă‚čă‚”ăƒŒăƒăƒŒăźæƒ…ć ±ă‚’ăƒ—ăƒ­ăƒ‘ăƒ†ă‚Łă«äżæŒă™ă‚‹ă‚Șăƒ–ă‚žă‚§ă‚Żăƒˆă‚’èż”ă™
  • db2_set_option — 掄続ăƒȘă‚œăƒŒă‚čあるいはă‚čăƒ†ăƒŒăƒˆăƒĄăƒłăƒˆăƒȘă‚œăƒŒă‚čたă‚Șăƒ—ă‚·ăƒ§ăƒłă‚’èš­ćźšă™ă‚‹
  • db2_special_columns — ăƒ†ăƒŒăƒ–ăƒ«ăźăƒŠăƒ‹ăƒŒă‚ŻèĄŒ ID ă‚«ăƒ©ăƒ ă‚’ć«ă‚€ç”æžœă‚»ăƒƒăƒˆă‚’èż”ă™
  • db2_statistics — ă‚€ăƒłăƒ‡ăƒƒă‚Żă‚čăźæƒ…ć ±ăŠă‚ˆăłăƒ†ăƒŒăƒ–ăƒ«ăźç”±èšˆæƒ…ć ±ă‚’ć«ă‚€ç”æžœă‚»ăƒƒăƒˆă‚’èż”ă™
  • db2_stmt_error — SQL æ–‡ăŒèż”ă™ SQLSTATE ă‚’ć«ă‚€æ–‡ć­—ćˆ—ă‚’èż”ă™
  • db2_stmt_errormsg — ç›Žèż‘ăź SQL æ–‡ăźă‚šăƒ©ăƒŒăƒĄăƒƒă‚»ăƒŒă‚žă‚’ć«ă‚€æ–‡ć­—ćˆ—ă‚’èż”ă™
  • db2_table_privileges — ăƒ‡ăƒŒă‚żăƒ™ăƒŒă‚čć†…ăźăƒ†ăƒŒăƒ–ăƒ«ăŠă‚ˆăłé–ąé€Łă™ă‚‹æš©é™æƒ…ć ±ă‚’ć«ă‚€ç”æžœă‚»ăƒƒăƒˆă‚’èż”ă™
  • db2_tables — ăƒ‡ăƒŒă‚żăƒ™ăƒŒă‚čć†…ăźăƒ†ăƒŒăƒ–ăƒ«ăŠă‚ˆăłé–ąé€Łă™ă‚‹ăƒĄă‚żăƒ‡ăƒŒă‚żă‚’ć«ă‚€ç”æžœă‚»ăƒƒăƒˆă‚’èż”ă™
add a note

User Contributed Notes 3 notes

up
3
igtoth at gmail dot com ¶
12 years ago
// IBM DB2 funcitons like MySQL (ODBC based)
// "Ighor Toth" <igtoth@gmail.com>
// Date: 08/05/2014

// usage:
// db2_connect(verbose,instance,username,password); -> also reads config file if nothing declared db2.conf.inc.php
// db2_query(db2_connect_return,sql)
// db2_fetch_array(result);
// db2_fetch_object(result);
// db2_display_table(db2_connect_return,sql); // select only

function db2_connect($verbose = null,$db2name = null,$username = null,$password = null) {
    if(!isset($verbose)){
        $verbose = TRUE; // TRUE or FALSE, if not set TRUE
    }
    if(!isset($db2name)){ // NOT DECLARED 
        include("db2.conf.inc.php"); // CHECK CONFIG FILE
        if(!isset($db2name)){
            if ($verbose == TRUE){
                echo ("DB2 Instance not selected");
                exit();
            } else {
                exit();
            }
        }
    } else if (!isset($username)){
        echo ("DB2 Instance username not specified");
        exit();    
    } 
    $db2conn = odbc_connect($db2name, $username, $password);
    if (($verbose == TRUE) && ($db2conn == 0)) {
        echo("Connection to database failed.");
        $sqlerror = odbc_errormsg($db2conn);
        echo($sqlerror);
    }
    return($db2conn);
}

function db2_query($db2conn,$sql){
    $result = odbc_exec($db2conn, $sql);
    if ($result == 0) {
        echo("QUERY = '$sql' FAILED.<br>\n");
        $sqlerror = odbc_errormsg($db2conn);
        echo($sqlerror);
    } else {
        // odbc_result_all prints all of the rows
        // for a result set ID as an HTML table
        return $result;
    }
}

 function db2_fetch_array($result, $rownumber=null){
    $array = array();
    if (!($cols = odbc_fetch_into($result, $result_array, $rownumber))) {
        return false;
    }
    for ($i = 1; $i <= $cols; $i++) {
        $array[odbc_field_name($result, $i)] = $result_array[$i - 1];
    }
    return $array;
}

function db2_fetch_object($result){
    if(function_exists("db2_fetch_object")) return db2_fetch_object($result);
    $rs = array();
    $rs_obj = false;
    if( odbc_fetch_into($result, $rs) ){
        foreach( $rs as $key=>$value ){
            $fkey = odbc_field_name($result, $key+1);
            $rs_obj->$fkey = trim($value);
        }
    }
    return $rs_obj;
}

function db2_display_table($db2conn,$sql) {
    // select all rows from the table
    if(!isset($db2conn)||!isset($sql)){
        echo("ERROR db2_display_table: Function missing arguments");
        exit();
    }
    $check = explode(" ",$sql);
    if($check[0]!="SELECT"){
        echo("ERROR db2_display_table: Not SELECT SQL query");
    }
    if ($db2conn != 0) {
        // odbc_exec returns 0 if the statement fails;
        // otherwise it returns a result set ID
        $result = odbc_exec($db2conn, $sql);
        if ($result == 0) {
            echo("SELECT statement failed.");
            $sqlerror = odbc_errormsg($db2conn);
            echo($sqlerror);
        } else {
            // odbc_result_all prints all of the rows
            // for a result set ID as an HTML table
            odbc_result_all($result);
        }
    }
}
up
1
Richard dot Ablewhite at gmail dot com ¶
17 years ago
There seems to be a lot of good documentation
for Linux users compiling PHP with DB2 support,
but decent Windows notes are minimal.

You do not need to install full DB2 clients to get DB2
working with DB2, all you need is the IBM Data
Server Driver for ODBC, CLI, and .NET which is only
16.1 meg.

You can download the driver from here:

Direct Link:
ftp://ftp.software.ibm.com/ps/products/db2/fixes2/englsh-us/
db2_v95/dsdriver/fp2/v9.5fp2_nt32_dsdriver_EN.exe

Home Page:
http://www-01.ibm.com/support/docview.wss?rs=71&uid=swg21287889

This includes both the drivers required and the PHP
dll php_ibm_db2_5.2.2.dll

Once installed the drivers do not setup the correct
path environmental variable,
so add the following to your path:

C:\Program Files\IBM\IBM DATA SERVER DRIVER\bin

Once thats done all should work! No massive
400meg client downloads required.

Whats even better about these drivers is that you
dont need to install them,
you can simply copy the bin directory to any server,
add it to your path and it will just work. 
This is great for anyone developing PHP-GTK applications,
I copy the bin directory into my php-gkt2 directory
and execute using the following batch script:

path = %PATH%;.\IBM DATA SERVER DRIVER\bin
php-win.exe %*

This lets me role out lightweight DB2 client desktop
apps that dont have to be installed,
can just be coppied from PC to PC or ran over a
network or from USB stick.

As your only installing the client drivers you wont be
able to catalog databases,
so always use the full connection string. Here is a
quick bit of code to get you started:

$database = 'databasename';
$user = 'user';
$password = 'password';
$hostname = '127.0.0.1';
$port = 50000;

$conn_string = "DRIVER={IBM DB2 ODBC DRIVER};DATABASE=$database;" .
  "HOSTNAME=$hostname;PORT=$port;".
  "PROTOCOL=TCPIP;UID=$user;PWD=$password;";
$conn = db2_connect($conn_string, '', '');

$query = 'SELECT * FROM TABLE';
$res = db2_prepare($conn, $query);
db2_execute($res);

while ($row = db2_fetch_array($res)) {
  print_r($row);
}
up
0
Exi ¶
18 years ago
The DB/2 Run-Time-Client can be found here:
http://www-1.ibm.com/support/docview.wss?rs=71&uid=swg21255394
Select the 'Runtime Client Installable for Windows' further down the page and download it. 
Clients for other platform (incl. 64-Bit Windows) are also available from that page.