Applications

The Applications page is accessed from Monitor | Applications.

 

The Demo applications included in Zend Server for IBM i are a convenient tool for gaining insight into how you can use the Zend 5250 Bridge API to extend your applications into a Web based environment.

 

There are several ways to view the Demo page:

A detailed list of the 5250 Bridge API functions that were used in order to create the Demo Applications can be found in the Working with the 5250 Bridge API section.

The source code for the Demo Applications can be found in /usr/local/zendsvr/5250/demos. A convenient way for developers to view the source files is by opening them in your Zend Studio IDE.

See Opening Files in Zend Studio for more information on how to view the code in Zend Studio for Eclipse.

Alternatively, you can view the content of the files from your preferred green screen emulation using the following commands:

  1. Change the directory to the location of the Demo files CD "/usr/local/zendsvr/5250/demos".
  2. Enter WRKLNK to list the contents of the demos directory.
  3. Select one of the Demo directories:

To view the code that generates the demo open index.php in the Green screen emulation using option 5 for each directory.

Applications window

Zend 5250 Emulator

The Zend 5250 Emulator provides browser access to i/OS resources and applications equivalent to an IBM© 5250 terminal without having to deploy telnet or terminal client applications.

Demo Applications window

5250 Bridge Demo Applications

The two Demo Applications demonstrate how the Zend 5250 Bridge API can be used to create interactive web-applications for 5250 programs. Clicking one of the demo application links open a new browser Window.

These demo applications were written in PHP using the Zend 5250 Bridge Procedural API Functions using functions to organize the code and HTML for the display.

Note:

The sample application code is located in: /usr/local/zendsvr/250/demos.

For more information about the Demo Applications and how you can recreate this functionality in your environment see:  Working with the Demo Applications.

Zend Navigator Demo Application

This Zend Navigator Demo Application shows the usage of PHP toolkit for IBM i functions. The source code for this application can be found in /usr/local/zendsvr/apaches2/htdocs/ Zend_Navigator_Demo. The main file is called login.php. The demo application has the following options:

Additional PHP Demo Scripts

The additional PHP demo scripts will help IBM i developers get started with PHP. These examples include the actual PHP code and the rendered result as follows:

Name

Code

Result in Browser

Hello World

<?php

echo "Hello, World!";

?>

Hello, World!

SQL Access

<html>

<head>

<title></title>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

</head>

<body>

<?php

$conn_resource = db2_connect("*LOCAL", "", "");

if (!$conn_resource) {

    echo "Connection failed. SQL Err:";

    echo db2_conn_error();

    echo "<br>";

    echo db2_conn_errormsg();

exit();

}

echo "Executing  SQL statement: SELECT * FROM ZENDSVR.SP_CUST WHERE CUST_ID > 1220 FOR FETCH ONLY"."<br>", "<br>";

/* Construct the SQL statement */

$sql = "SELECT * FROM ZENDSVR.SP_CUST WHERE CUST_ID > ? FOR FETCH ONLY";

/* Prepare, bind and execute the DB2 SQL statement */

$stmt= db2_prepare($conn_resource, $sql);

$lower_limit = 1220; //from the CUST_ID value

$flds = db2_num_fields($stmt);

if($flds > 0 )

{

//show Table Header (analyze result set)

    echo "<table border=1>";

    echo "<tr>";

    for($i=0; $i<$flds; $i++)

    {

        echo '<td width="20%">';

        $aa = db2_field_name($stmt, $i);

        echo $aa;

        echo "</td>";

    }     

     

    echo "</tr>";

//Execute statement , uses a binding of parameters  

db2_bind_param($stmt, 1, "lower_limit", DB2_PARAM_IN);

$result = db2_execute($stmt);

       if (!$result) {

           echo 'The db2 execute failed. ';

           echo 'SQLSTATE value: ' . db2_stmt_error();

           echo ' Message: ' .   db2_stmt_errormsg();

        }

        else

        {             

          while ($row = db2_fetch_array($stmt))  

          {

              echo "<tr>";               

              for($i=0; $i<$flds; $i++){

                echo '<td width="20%">';                 

                echo $row[$i] . '&nbsp';

                echo "</td>";                      

              }             

            echo "</tr>";             

          }

       }                    

     echo  "</table>";

}

?>

Click Here to see Result

SQL Access using Zend Framework DB2 adapter

<html>

<head>

<title></title>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

</head>

<body>

<?php

require_once 'Zend/Db/Adapter/Db2.php';

$config = array(

                'dbname'   => '*LOCAL',

                'username' => '',

                'password' => '',

                'os'=>'i5',

                'driver_options'=> array("i5_commit" =>DB2_I5_TXN_READ_UNCOMMITTED,

                                            "autocommit"=>DB2_AUTOCOMMIT_OFF,

                                            "i5_lib"=>'ZENDSVR'));

             

$conn = new Zend_Db_Adapter_Db2($config);

echo "Executing  SQL statement: SELECT * FROM ZENDSVR.SP_CUST WHERE CUST_ID > 1220 FOR FETCH ONLY"."<br>", "<br>";

/* Construct the SQL statement */

$sql = "SELECT * FROM ZENDSVR.SP_CUST WHERE CUST_ID > ? FOR FETCH ONLY";

$lower_limit = 1220; //from the CUST_ID value

/* Prepare, bind and execute the DB2 SQL statement */

$stmt = $conn->query($sql, $lower_limit);

echo '<table border="1">';

$i = 0;

while (($row = $stmt->fetch(Zend_Db::FETCH_ASSOC)) !== false) {

    if($i == 0){

       $ColumnNames = ShowTableHeader($row);

    }

     

    ShowTableRow($ColumnNames, $row );

    $i++;

}

echo '</table>';

exit();

function ShowTableHeader( $row )

{

    $flds  = count( $row );         

    if ($flds > 0) {

        $fieldNames = array_keys($row);             

        echo '<tr>';

        foreach ($fieldNames as $field) {         

            echo "<td>{$field}</td>";

        }     

        echo '</tr>';

    }

     

    return $fieldNames;

}

function ShowTableRow($ColumnNames , $row )

{

    echo '<tr>';

    foreach ($ColumnNames as $ColumnName) {

        if(trim($row[$ColumnName]) === ''){

            echo "<td>&nbsp</td>";

        }

        else {

            echo "<td>{$row[$ColumnName]}</td>";

        }

    }

    echo '</tr>';

}

?>

Click Here to see Result

SQL Access to MYSQL database

<html>

<head>

<title></title>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

</head>

<body>

<?php

$conn_resource  = mysql_connect("localhost", "root", "");

if (!$conn_resource) {

    echo "Connection failed. SQL Err:";

    echo mysql_error();

    exit();

}

$db =  mysql_select_db("mysql", $conn_resource);

if(!$db)

{

    echo "database did not select. SQL Err:";

    echo mysql_error();

    exit();

}

echo "Executing  SQL statement: select * from user";

echo "<br><br>";

$query = "select * from user";

$stmt = mysql_query($query, $conn_resource);

if(!is_resource($stmt)){

   echo "query  failed. ";

   echo  mysql_error();

   exit();

}

echo '<table border="1">';

$FirstFetch = true;

while ( ($row = mysql_fetch_assoc($stmt))  !== false){

    if($FirstFetch ){

       $ColumnNames = ShowTableHeader( $row );

       $FirstFetch = false;

    }     

   ShowTableRow($ColumnNames , $row );     

}

echo '</table>';

function ShowTableHeader( $row )

{

    $flds  = count( $row );         

    if ($flds > 0) {

        $fieldNames = array_keys($row);             

        echo '<tr>';

        foreach ($fieldNames as $field) {         

            echo "<td>{$field}</td>";

        }     

        echo '</tr>';

    }     

    return $fieldNames;

}

function ShowTableRow($ColumnNames , $row )

{

    echo '<tr>';

    foreach ($ColumnNames as $ColumnName) {

        if(trim($row[$ColumnName]) === ''){

            echo "<td>&nbsp;</td>";

        }

        else {

            echo "<td>{$row[$ColumnName]}</td>";

        }

    }

    echo '</tr>';

}

?>  

Click Here to see Result

Program Call

#Valid code value is 1 or 2.

<?php

$user     = '';

$password = '';

$conn_resource = i5_connect('127.0.0.1',$user,$password );

if($conn_resource === false){

    echo "Connection failed. SQL Err:" . i5_errno();

    echo "<br>";

    echo  i5_errormsg();

    exit();

}

$desc = array (

array ("name"=>"CODE", "io"=>I5_INOUT, "type" => I5_TYPE_CHAR, "length"=> "10"),

array ("name"=>"DESC", "io"=>I5_INOUT, "type" => I5_TYPE_CHAR, "length"=> "10")

);

$prog = i5_program_prepare("ZENDSVR/COMMONPGM", $desc);

if ($prog === FALSE)

{

   $errorTab = i5_error();

   echo "Program prepare failed <br>\n";

   var_dump($errorTab);

   die();

}

/* Execute Program */

$paramin = array ("CODE"=>$_POST["code"],"DESC"=>" ");

$paramout = array("CODE"=>"var1","DESC"=>"var2");

$ret = i5_program_call($prog, $paramin, $paramout);

if ($ret === FALSE)

{

   $errorTab = i5_error();

   echo "FAIL : i5_program_call failure code <br>";

   var_dump($errorTab);

   die();

}

     

echo "The return values are: <br>", "Code: ", $var1, "<br> Description: ", $var2,"<br>";

// Close program call

i5_program_close($prog);

// Close connection

i5_close($conn_resource);

?>

i5_program_call.png

LDAP

<?php

if( isset( $_POST['server']) )

    $server = $_POST['server'];

     

if(isset( $_POST['user']))

    $username = $_POST['user'];

if( isset( $_POST['pass']) )     

    $password = $_POST['pass'];

     

$serverURL = "ldap://". $server ."/";

$ds = ldap_connect( $serverURL );

//try to connect as anonimus

if($username === NULL || password == NULL){  

    $anonymous  = ldap_bind( $ds );  

    if ( !$anonymous  ) {  

        // test failed, try to connect with user/password  

         echo "LDAP bind as anonimus failed. Try to connect with User & Password ...";

         exit();  

    }  

}

  

 $login = ldap_bind( $ds, $username, $password );  

 if($login){

    echo "LDAP bind for user $username successful...";

    }

 else {

    echo "LDAP bind for user $username  failed...";

  }

  

?>  

i5_ldap.png

 

 

 

Related Links

Related Links:

Working with the Zend 5250 Bridge

Zend 5250 Bridge API

Introduction to the PHP Toolkit for IBM i

Zend Server for IBM i Installation Guide

Troubleshooting the Zend 5250 Bridge