Zend Server User Guide > Concepts > Demo Scripts

Demo Scripts

To help IBM i developers get quickly acquainted with PHP, Zend Server allows you to install an application that includes example PHP scripts that show-case popular workflows for utilizing Zend Server.

To run and view the source code, the application containing the scripts needs to be installed. See Working with Demo Scripts for more information.

Name Code

Hello World

<?php

echo "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 ZENDSVR6.SP_CUST WHERE CUST_ID > 1220 FOR FETCH ONLY"."<br>", "<br>";

/* Construct the SQL statement */

$sql = "SELECT * FROM ZENDSVR6.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%">';

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

echo $name;

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>";

}

?>

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"=>'ZENDSVR6'));

 

$conn = new Zend_Db_Adapter_Db2($config);

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

/* Construct the SQL statement */

$sql = "SELECT * FROM ZENDSVR6.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>';

}

?>

SQL Access to MySQL DB

<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>';

}

?>

LDAP Connection

<?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...";

}

?>

PHP Toolkit Demo Scripts

See Toolkit Sample Scripts.

 

 

Related Links

Related Links:

Working with Demo Scripts

Toolkit Sample Scripts

 

 

 

© 1999-2013 Zend Technologies, Ltd. All rights reserved.