Results 1 to 4 of 4
  1. #1
    Join Date
    Dec 2010
    Posts
    2

    Unanswered: Using ODBC to call PHP command - HELP PLS :)

    Hello everyone.
    This is an interesting problem. I have this code and I want to call
    FTP RMTSYS('') command through ODBC from PHP.
    Nothing happens. When I issue the command in DBVisualizer:
    CALL QSYS.QCMDEXC('FTP RMTSYS(iSeries_SERVER)', 0000000020.00000);
    I get this error:
    Program contains commands only valid when run interactively.
    Application error. CPD0772 unmonitored by QSNDEVQ at statement
    0000000001, instruction X'0000'.
    FTP client exit error.


    Now, this command can be run in batch mode when in CL or RPG-ILE programme. Can it be run this way, from ODBC in PHP?

    The following code works until it reaches the command in question.
    Any help or hint would be appreciated




    <?php


    /* Starting PHP session */
    session_start();

    /* Declaring varialbes */

    $_SESSION[server]= 'iSeries_SERVER';
    $_SESSION[user]= 'username';
    $_SESSION[pass]= 'password';

    $up = "up";
    $lib = "lib";
    $libu = "libu";
    $lpar = "lpar";
    $table = 'library.ftpin';

    /* Creating connection towards iSeries server */

    $conn = odbc_connect($_SESSION[server],$_SESSION[user],$_SESSION[pass]);
    if ($conn == false) {
    echo " Not connected to database ! ";
    }
    else
    {
    echo " Connected to database ! ";
    };


    /* Creating INPUT file for FTP */

    $create_ftpin = "create table library.ftpin (rcdfmt char(300))";
    $crttbl_res = odbc_do($conn, $create_ftpin);

    /* Creating OUTPUT file for FTP */

    $create_ftpout = "create table library.ftpout (rcdfmt char(300))";
    $crttbl_res = odbc_do($conn, $create_ftpout);


    /* Inserting values into INPUT file for FTP */

    $insert = "insert into library.ftpin values
    'library library',
    'bin',
    'namefmt 1',
    'quote rcmd CRTLIB LIB(TEMPX)',
    'cd tempx.lib',
    'lcd library.lib',
    'put transfer.file',
    'quote rcmd RSTOBJ obj(*all) savlib(lib) dev(*savf) savf(tempx/transfer) mbropt(*all) alwobjdif(*all) rstlib(TEMPXX)',
    'quote rcmd RMVLIBLE LIB(TEMPX)',
    'quote rcmd DLTLIB LIB(TEMPX)',
    'close',
    'quit'
    ";

    $insrt_res = odbc_do($conn, $insert);


    /* Calling subsequent commands from PHP through ODBC */

    $qry1="CALL QSYS.QCMDEXC('CRTSAVF FILE(library/TRANSFER)', 0000000029.00000)";
    $stmt1 = odbc_prepare($conn, $qry1);
    $result1 = odbc_execute($stmt1);

    $qry2="CALL QSYS.QCMDEXC('CRTSRCPF FILE(library/ftpout) MBR(ftpout)', 0000000063.00000)";

    $qry2 = "CALL QSYS.QCMDEXC ('SAVOBJ OBJ(*ALL) LIB(library) DEV(*SAVF) OBJTYPE(*ALL) SAVF(library/TRANSFER) SAVACT(*SYNCLIB)', 0000000092.00000)";
    $stmt2 = odbc_prepare($conn, $qry2);
    $result2 = odbc_execute($stmt2);

    $qry3 = "CALL QSYS.QCMDEXC('OVRDBF FILE(INPUT) TOFILE(library/ftpin)', 0000000039.00000)";
    $stmt3 = odbc_prepare($conn, $qry3);
    $result3 = odbc_execute($stmt3);

    $qry4 = "CALL QSYS.QCMDEXC('OVRDBF FILE(OUTPUT) TOFILE(library/ftpout)', 0000000041.00000)";
    $stmt4 = odbc_prepare($conn, $qry4);
    $result4 = odbc_execute($stmt4);

    /* Everything works until here! */

    $qry5 = "CALL QSYS.QCMDEXC('FTP RMTSYS(ASUDOT21)', 0000000020.00000)";
    $stmt5 = odbc_prepare($conn, $qry5);
    $result5 = odbc_execute($stmt5);

    $qry6 = "CALL QSYS.QCMDEXC('DLTOVR FILE(INPUT OUTPUT)', 0000000024.00000)";
    $stmt6 = odbc_prepare($conn, $qry6);
    $result6 = odbc_execute($stmt6);

    $qry8="CALL QSYS.QCMDEXC('DSPF FILE(library/ftpout)', 0000000063.00000)";

    $qry9="CALL QSYS.QCMDEXC('DLTF FILE(library/ftpout)', 0000000063.00000)";

    $qry10="CALL QSYS.QCMDEXC('CLRLIB library', 0000000063.00000)";



    odbc_close($conn);
    session_destroy();

  2. #2
    Join Date
    Jan 2007
    Location
    Jena, Germany
    Posts
    2,721
    I don't know what exactly you are doing, because I don't know what the stored procedure QCMDEXC() is supposed to be doing. Maybe you want to explain that?

    In any case, this piece has a few problems:
    Code:
    $insert = "insert into library.ftpin values
    'library library',
    'bin',
    'namefmt 1',
    'quote rcmd CRTLIB LIB(TEMPX)',
    'cd tempx.lib',
    'lcd library.lib',
    'put transfer.file',
    'quote rcmd RSTOBJ obj(*all) savlib(lib) dev(*savf) savf(tempx/transfer) mbropt(*all) alwobjdif(*all) rstlib(TEMPXX)',
    'quote rcmd RMVLIBLE LIB(TEMPX)',
    'quote rcmd DLTLIB LIB(TEMPX)',
    'close',
    'quit'
    ";
    - The SQL syntax is not correct; you are missing ( and ) for each row
    - You assume that rows in a table are ordered by something, i.e. you assume the rows will be stored in the same order as you inserted them. This assumption is simply wrong.
    - You have basically no error handling in the code. I suggest you add that and start to debug your program that way.
    Knut Stolze
    IBM DB2 Analytics Accelerator
    IBM Germany Research & Development

  3. #3
    Join Date
    Dec 2010
    Posts
    2
    Hi stolze and thank you for the reply.
    This code actually works, well, most part of it
    It fills single record FTPIN file with FTP commands in order as it is written. This file is then used for input on iSeries FTP command to be processed when needed. And it is needed, as you see, to transfer the save file to from one LPAR to the other and restore that save file in library of choice.
    QCMDEXC is an API on iSeries that is used to deploy single CL commands.
    Code works to the point of FTP RMTSYS command. This command can be used in batch as well as interactively. Now, when I deploy it through CL or RPG-ILE program it works, but when I deploy it like any other command through QCMDEXC API it says that this command can be run only interactively.
    This is why I posted this example and the question if anyone knows about this problem? How to go around and deploy FTP RMTSYS command from QCMDEXC from PHP? And if anyone know is there a limitation on which command cannot be deployed by QCMDEXC?

  4. #4
    Join Date
    Jan 2007
    Location
    Jena, Germany
    Posts
    2,721
    You haven't responded to any of the problems I mentioned:
    - SQL does not guarantee that rows are returned in a specific order unless you have an ORDER BY clause in your query. Since your table does not have a line number or so, you simply have no guarantee that the FTP commands are executed in expected sequence.
    - You should fix the syntax problems. While it may work on your system, it is causing problems.
    - You should add error handling if you want to know why your code isn't working.
    Knut Stolze
    IBM DB2 Analytics Accelerator
    IBM Germany Research & Development

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •