使用DB2 connect持续循环PHP

时间:2015-08-24 19:02:28

标签: php sql db2

这是我在这里的第一篇文章;我主要写SQL。我的任务是编写从旧表到两个新表的转换脚本。我对PHP知之甚少,如果想更好地了解如何找到解决方案,我将不胜感激。

include_once 'authorization.php';
include_once 'ToolkitService.php';
// To reuse an existing database connection as the toolkit transport, specify an existing database resource and a DB2/I5 naming flag
$i5NamingFlag = DB2_I5_NAMING_ON; // ON means use slash '/' and liblists
// connect to db
$dbConn = db2_pconnect('$server', '$user', '$pass' (array('i5_naming'=>$i5NamingFlag)));
if (!$dbConn) die('Could not connect to db: ' . db2_conn_error() . ' ' . db2_conn_errormsg());
// successful db connection. Pass into toolkit
$ToolkitServiceObj = ToolkitService::getInstance($dbConn, $i5NamingFlag);

//SQL statement to select records to be converted
$sqlselect = "SELECT
                  LOCATION, CONTRACT, CUSTNAME, CUSTNUM , DOCUMENT_DATE, SCAN_DATE,
                  DOCUMENT_TYPE_ID, DOCUMENT_PATH, DOCUMENT_NAME , ARCHIVED,
                  DOCUMENT_DESC, USERNAME
          FROM
               WAPSCANP.DOCUMENTP;";

$result = db2_exec($dbConn,$sqlselect);

while ($row = db2_fetch_assoc($result)) {

$sqlinsert = "INSERT INTO CARDATAT.DSSDOCFLP
(
    DFDBID      ,
    DFDFID      ,
    DF_RSTRD_FLG,
    DFLOC       ,
    DFSSTAMP    ,
    DFCTID      ,
    DFNAME      ,
    DFSUBDIR    ,
    DFTRASH     ,
    DFDESC      ,
    DFSRC       ,
    DFCUSER     ,
    DFCSTAMP    ,
    DFMUSER     ,
    DFMSTAMP
)
SELECT
    CDID,
    0                  ,
    0                  ,
    '{$row['LOCATION']}',
    '{$row['SCAN_DATE']}',
    (SELECT CTID FROM CARDATAT.DSSCFGTPP AS TPP
            JOIN WAPSCANP.DOCTYPEP AS TYPEP
                 ON TYPEP.NAME=TPP.CTNAME AND TYPEP.ID='{$row['DOCUMENT_TYPE_ID']}'),
    '{$row['DOCUMENT_NAME']}',
    '{$row['DOCUMENT_PATH']}',
    0                  ,
    '{$row['DOCUMENT_DESC']}' ,
    'S'                 ,
    '{$row['USERNAME']}',
    '{$row['DOCUMENT_DATE']}'||' 00:00:00',
    ''                 ,
    '0001-01-01 00:00:00'
  FROM CARDATAT.DSSCFGDBP
  where CDDBDESC='Field Users'";
db2_exec($dbConn, $sqlinsert);
{
    foreach ($row AS $key){
        $ret = db2_last_insert_id($dbConn);
        $sqlinsert1 = "INSERT INTO CARDATAT.DSSATTRP
(
    ATCAID,
    ATDFID,
    ATVALUE
)
SELECT

    CAID,
    '{$ret}',
    '{$row['CUSTNAME']}'
    FROM  CARDATAT.DSSCFGATP
     where  CAFLDNME='Customer Name' and CACTID=(SELECT CTID FROM CARDATAT.DSSCFGTPP AS TPP
            JOIN WAPSCANP.DOCTYPEP AS TYPEP
                 ON TYPEP.NAME=TPP.CTNAME AND TYPEP.ID='{$row['DOCUMENT_TYPE_ID']}');";
        db2_exec($dbConn, $sqlinsert1);



    }
}


}
?>

0 个答案:

没有答案