2.4a informix application development survey lab · this lab is especially useful for database...

31
IBM Informix 11.5 Informix Application Development and Extensibility Choose one of the following labs: Connecting to Informix Databases Using JDBC, ODBC, ESQL/C and PHP Java Application Development Informix 4GL The Basic Text Search (BTS) DataBlade

Upload: others

Post on 15-Mar-2020

3 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 2.4a Informix Application Development Survey Lab · This lab is especially useful for database administrators who are asked to support many different development environments. 2

IBM Informix 11.5

Informix Application Development and Extensibility

Choose one of the following labs:

Connecting to Informix Databases Using JDBC, ODBC, ESQL/C and PHP

Java Application Development

Informix 4GL

The Basic Text Search (BTS) DataBlade

Page 2: 2.4a Informix Application Development Survey Lab · This lab is especially useful for database administrators who are asked to support many different development environments. 2

2

Information Management Partner Technologies

IBM Informix 11.5

Connecting to Informix Databases Using JDBC, ODBC, ESQL/C and PHP

I

Information Management Partner Technologies

Page 3: 2.4a Informix Application Development Survey Lab · This lab is especially useful for database administrators who are asked to support many different development environments. 2

3

Contents

1. INTRODUCTION ...........................................................................................4

2. SUGGESTED READING...............................................................................4

3. CONNECTING TO AN INFORMIX DATABASE USING THE IBM DATA SERVER DRIVER FOR JDBC .............................................................................5

3.1 WHAT IS JDBC?.......................................................................................5 3.2 WHAT IS A JDBC DRIVER?.........................................................................6 3.3 WHAT ARE DIFFERENT TYPES OF JDBC DRIVERS? .......................................6 3.4 JDBC DRIVERS FOR INFORMIX ...................................................................7 3.5 STARTING INFORMIX..................................................................................8 3.6 INSTALLING THE IBM DATA SERVER DRIVER FOR JDBC AND SQLJ ..............9 3.7 RUNNING A SAMPLE JAVA PROGRAM TO TEST THE CONNECTIVITY ................11

4. CONNECTING TO AN INFORMIX DATABASE USING THE IBM INFORMIX ODBC DRIVER ................................................................................14

4.1 WHAT IS ODBC?....................................................................................14 4.2 WHAT IS THE IBM INFORMIX ODBC DRIVER? ............................................14 4.3 ODBC COMPONENT OVERVIEW................................................................15 4.4 INSTALLING THE IBM INFORMIX ODBC DRIVER..........................................16 4.5 RUNNING A SAMPLE C PROGRAM TO CHECK THE CONNECTIVITY ..................19

5. PROGRAMMING WITH INFORMIX ESQL/C..............................................20

5.1 WHAT IS INFORMIX ESQL/C? ..................................................................20 5.2 HOW CAN YOU CREATE AN ESQL/C PROGRAM? ........................................20 5.3 INSTALLING THE IBM INFORMIX ESQL/C DRIVER ......................................21 5.4 RUNNING A SAMPLE ESQL/C PROGRAM TO TEST THE CONNECTIVITY ........23

6. CONFIGURING PHP ENVIRONMENT FOR INFORMIX DATABASES .....24

6.1 WHAT IS PHP?.......................................................................................24 6.2 INFORMIX INTERFACES FOR PHP..............................................................24 6.3 SETTING UP THE PHP APPLICATION ENVIRONMENT FOR INFORMIX...............26 6.4 RUNNING A SAMPLE PROGRAM TO CHECK THE PHP CONFIGURATION ...........29 6.5 RUNNING A SAMPLE PHP PROGRAM TO TEST THE INFORMIX DATABASE

CONNECTIVITY ......................................................................................29

Page 4: 2.4a Informix Application Development Survey Lab · This lab is especially useful for database administrators who are asked to support many different development environments. 2

4

1. Introduction

This lab describes how to install, configure and use JDBC, ODBC, ESQL/C and PDO drivers to connect to Informix databases from Java, C, ESQL/C, and PHP applications respectively. This lab is especially useful for database administrators who are asked to support many different development environments.

2. Suggested Reading

IBM Informix Dynamic Server 11.5 Information Center

This is the official online searchable Informix product documentation.

http://publib.boulder.ibm.com/infocenter/idshelp/v115/index.jsp

IBM Data Server Driver for JDBC and SQLJ for Informix guide

This publication describes how to use the IBM Data Server Driver for JDBC and SQLJ, which allows you to write client applications that can connect to DB2 and Informix data servers.

www.ibm.com/support/docview.wss?uid=swg27010058

IBM Informix ODBC Driver Programmer’s Manual

This manual is a user guide and reference manual for IBM Informix ODBC Driver, which is the Informix implementation of the Microsoft Open Database Connectivity (ODBC) interface, Version 3.0. This manual explains how to use the IBM Informix ODBC Driver application programming interface (API) to access an Informix database and interact with an Informix database server.

www.ibm.com/support/docview.wss?uid=swg27013893

Page 5: 2.4a Informix Application Development Survey Lab · This lab is especially useful for database administrators who are asked to support many different development environments. 2

5

IBM Informix ESQL/C Programmer's Manual

This manual describes the features that make up the IBM Informix implementation of embedded SQL for C.

www.ibm.com/support/docview.wss?uid=swg27013893

Developing PHP Applications for IBM Data Servers

This IBM Redbook contains comprehensive information about how to develop and deploy Web solutions using PHP and IBM Data Servers, including Informix.

www.redbooks.ibm.com/abstracts/sg247218.html

A step-by-step how-to guide to install, configure, and test a Linux, Apache, Informix, and PHP server

This developerWorks article shows how to install, configure, and test a Linux, Apache, Informix, and PHP (LAIP) server. LAIP provides a very powerful and dynamic mixture for a Web server.at the following link.

www.ibm.com/developerworks/db2/library/techarticle/dm-0606bombardier

3. Connecting to an Informix Database Using the IBM Data Server Driver for JDBC

3.1 What is JDBC? Java database connectivity (JDBC) is the Java specification of a standard application programming interface (API) that allows Java programs to access database management systems. The JDBC API consists of a set of interfaces and classes written in the Java programming language.

Using these standard interfaces and classes, programmers can write Java applications that connect to databases, send queries written in structured query language (SQL), and process the results.

Page 6: 2.4a Informix Application Development Survey Lab · This lab is especially useful for database administrators who are asked to support many different development environments. 2

6

3.2 What is a JDBC driver? The JDBC API defines the Java interfaces and classes that programmers use to connect to databases and send queries. A JDBC driver implements these interfaces and classes for a particular DBMS vendor.

3.3 What are different types of JDBC drivers? There are four types of JDBC drivers:

JDBC-ODBC bridge plus ODBC driver, also called Type 1 driver

o Translates JDBC API calls into Microsoft ODBC calls that are then passed to the ODBC driver.

o The ODBC binary code must be loaded on every client computer that uses this type of driver.

o ODBC is an acronym for Open Database Connectivity.

Native-API, partly Java driver, also called Type 2 driver

o Converts JDBC API calls into DBMS-specific client API calls.

o Like the bridge driver, this type of driver requires that some binary code be loaded on each client computer.

JDBC-Net, pure-Java driver, also called Type 3 driver

o Sends JDBC API calls to a middle-tier server that translates the calls into the DBMS-specific network protocol.

o The translated calls are then sent to a particular DBMS.

Native-protocol, pure-Java driver, also called Type 4 driver

o Converts JDBC API calls directly into the DBMS-specific network protocol without a middle tier.

o This allows the client applications to connect directly to the database server.

Page 7: 2.4a Informix Application Development Survey Lab · This lab is especially useful for database administrators who are asked to support many different development environments. 2

7

3.4 JDBC drivers for Informix For Informix, there are two drivers that implement the JDBC specification:

Informix JDBC Driver

IBM Data Server Driver for JDBC and SQLJ, also called Java Common Client (JCC)

The Informix JDBC Driver uses the Informix proprietary SQLI protocol whereas the IBM Data Server Driver uses the Distributed Relational Database Architecture (DRDA) protocol.

In this lab you will use the IBM Data Server Driver for JDBC and SQLJ as that is the preferred driver for new Java applications.

The IBM Data Server Driver for JDBC and SQLJ is also integrated with DB2. This capability means that the common features of thedriver allow you to write client applications that can use both DB2 and Informix data servers.

The IBM Data Server Driver for JDBC and SQLJ is compliant with the Sun Microsystems JDBC 3.0 and JDBC 4.0 specifications.

The following table should serve as an overview of features that might impact your decision on which driver to use (as of IBM Data Server Driver Version 3.53).

Informix JDBC Driver

IBM Data Server Driver

DRDA Connections X

SQLI Connections X

Informix version < 11.10 X

JDBC 4.0 Functionality X

INTERVAL,opaque- and user-defined data types, collection data types

X

Automatic client reroute (failover) X

Page 8: 2.4a Informix Application Development Survey Lab · This lab is especially useful for database administrators who are asked to support many different development environments. 2

8

Note: This table is not a complete list of differences. For more information see:

http://publib.boulder.ibm.com/infocenter/idshelp/v115/topic/com.ibm.jccids.doc/com.ibm.db2.luw.apdv.java.doc/doc/r0052865.htm

3.5 Starting Informix Although it is not required to start the Informix instance before installing the JDBC driver, you will need the Informix database to be up and running in order for the sample Java program to work.

Follow the steps below to start the Informix instance:

Login into the VMWare image as the informix user.

Note: Refer to the document entitled “VMWare Basics” for information about how to start and login to the VMWare Image.

Right click on the desktop area and choose Open Terminal.

Set the environment for the database server by typing the

following commands in the command terminal.

cd scripts

. setDemo

Page 9: 2.4a Informix Application Development Survey Lab · This lab is especially useful for database administrators who are asked to support many different development environments. 2

9

Enter the following command in the command terminal to see if the Informix Server is up and running.

onstat -

o If the Informix server is NOT running then you will see the following message:

Shared memory not initialized for INFORMIXSERVER

‘demo_on’

o If the Informix Server is running then you will see a message similar to the following:

IBM Informix Dynamic Server Version 11.50.UC1W1DE --

On-Line – Up 00:00:15 – 38204 Kbytes

Enter the following command to start the server ONLY if it is NOT already running:

oninit

3.6 Installing the IBM Data Server Driver for JDBC and SQLJ Java SDK Requirement: Before you install the IBM Data Server Driver for JDBC and SQLJ, you must have a Java SDK installed on your computer. For JDBC 3.0 functionality, you need Java SDK 1.4.2 or later. If you want to use JDBC 4.0 functionality, you need an SDK for Java 1.6 or later.

Important: Java version 1.5.0 has already been installed on the VM image so you will not have to install the SDK for this exercise.

The following are the steps outline how to install the IBM Data Server Driver for JDBC:

Obtain the driver file by downloading it from:

https://www14.software.ibm.com/webapp/iwm/web/reg/download.do?lang=en_US&source=swg-informixfpd&S_PKG=dl&cp=UTF-8

Page 10: 2.4a Informix Application Development Survey Lab · This lab is especially useful for database administrators who are asked to support many different development environments. 2

10

Extract the zip file into an empty directory.

The zip file contains the following files:

* db2jcc.jar * db2jcc4.jar

* sqlj.zip * sqlj4.zip

Important: For this lab, the JDBC driver files have already been downloaded and extracted for you.

Important: the CLASSPATH variable has already been set.

Normally you would have to modify the CLASSPATH environment variable to include the appropriate files:

For JDBC, include db2jcc.jar in the CLASSPATH if you plan to use the version of the IBM Data Server Driver for JDBC and SQLJ that includes only JDBC 3.0 and earlier functions.

Include db2jcc4.jar in the CLASSPATH if you plan to use the version of the IBM Data Server Driver for JDBC and SQLJ that includes JDBC 4.0 and later functions, as well as JDBC 3.0 and earlier functions.

Important: Include db2jcc.jar or db2jcc4.jar in the CLASSPATH. Do NOT include both files.

Enter the following command at the command prompt to verify the CLASSPATH (it should contain db2jcc.jar):

echo $CLASSPATH

Configure a new server alias in the SQLHOSTS file for the drsoctcp connection protocol.

Important: There is already an entry for the Informix server in the SQLHOSTS file. You can verify this by locating the SQLHOSTS file and looking at its contents.

Page 11: 2.4a Informix Application Development Survey Lab · This lab is especially useful for database administrators who are asked to support many different development environments. 2

11

Enter the following command at the command prompt to locate the SQLHOSTS file used by the instance.

echo $INFORMIXSQLHOSTS

This displays the name and the location of the SQLHOSTS file.

Look at the contents of the file:

cat /opt/IBM/informix/etc/sqlhosts.demos

You should see a drsoctcp entry for the demo_on server with the name demo_ondrda. It is listening for connections on port number 9089.

3.7 Running a sample Java program to test the connectivity We have provided a sample Java program that can be used to test the connection to an Informix database using the IBM Data Server Driver for JDBC.

Using a text editor, enter and save the following lines of code in a file called Connect2IDS.java in the /home/informix/scripts/java directory.

Important: This file is available to you in the /home/informix/scripts/java directory. You do NOT need to type the code below.

Page 12: 2.4a Informix Application Development Survey Lab · This lab is especially useful for database administrators who are asked to support many different development environments. 2

12

// Program to test connection to an Informix dB using JCC driver

import java.util.*;

import java.sql.*;

public class Connect2IDS {

public static void main( String[] args) throws SQLException, ClassNotFoundException {

Connection conn;

PreparedStatement pstmt;

ResultSet rs;

String URL = "jdbc:ids://ids1150srvr:9089/stores";

String user = "informix";

String password = "informix";

String driverClass = "com.ibm.db2.jcc.DB2Driver";

Class.forName( driverClass );

conn = DriverManager.getConnection(URL, user, password);

if (conn != null) {

System.out.println("Got a connection to the DB");

String [] tableTypes = { "TABLE", "VIEW" };

DatabaseMetaData dbmd = conn.getMetaData();

rs = dbmd.getTables(null, null, null, tableTypes);

while (true == rs.next()) {

System.out.println( rs.getString(2) + "." + rs.getString(3) + " [" + rs.getString(4) + "]");

}

conn.close();

}

return;

}

}

Page 13: 2.4a Informix Application Development Survey Lab · This lab is especially useful for database administrators who are asked to support many different development environments. 2

13

Compile the java program using the following commands:

cd /home/informix/scripts/java

javac Connect2IDS.java

A file with the name Connect2IDS.class will be generated after successfully compiling the program.

Run the Java program after successful compilation:

java Connect2IDS

After successful execution, the program will output the list of tables in the STORES database.

Page 14: 2.4a Informix Application Development Survey Lab · This lab is especially useful for database administrators who are asked to support many different development environments. 2

14

4. Connecting to an Informix Database Using the IBM Informix ODBC Driver

4.1 What is ODBC? Open Database Connectivity (ODBC) is a specification for a database Application Programming Interface (API). Microsoft ODBC, Version 3.0, is based on the Call Level Interface specifications from X/Open and the International Standards Organization/International Electromechanical Commission (ISO/IEC). ODBC supports SQL statements with a library of C functions. An application calls these functions to implement ODBC functionality.

4.2 What is the IBM Informix ODBC driver? The IBM Informix ODBC Driver implements the Microsoft Open Database Connectivity (ODBC) Version 3.0 standard.

IBM Informix ODBC applications enable you to perform the following operations:

1. Connect to and disconnect from data sources

2. Retrieve information about data sources

3. Retrieve information about the ODBC Driver

4. Set and retrieve ODBC Driver options

5. Prepare and send SQL statements

6. Retrieve SQL results and process the results dynamically

7. Retrieve information about SQL results and process the information dynamically

ODBC lets you allocate storage for results before or after the results are available. This feature lets you determine the results and the action to take without the limitations that predefined data structures impose. ODBC does not require a pre-processor to compile an application program.

Page 15: 2.4a Informix Application Development Survey Lab · This lab is especially useful for database administrators who are asked to support many different development environments. 2

15

4.3 ODBC component overview ODBC with the IBM Informix ODBC Driver can include the following components:

Driver manager

An application can link to a driver manager, which links to the driver specified by the data source. The driver manager also checks parameters and transitions. On most UNIX platforms, the ODBC Driver Manager can be purchased from a third-party vendor. The Data Direct ODBC driver manager is shipped with the CSDK bundle for Sun Solaris 32-bit and IBM AIX 32-bit platforms. On Microsoft Windows platforms, the ODBC Driver Manager is a part of the OS.

IBM Informix ODBC Driver

The driver provides an interface to an Informix database server. Applications can use the driver in the following configurations:

To link to the ODBC driver manager

To link to the Driver Manager Replacement and the driver

To link to the driver directly

Data sources

The driver provides access to the following data sources:

Database management systems (DBMS), including a database server.

Databases

Operating systems and network software for accessing the database.

Page 16: 2.4a Informix Application Development Survey Lab · This lab is especially useful for database administrators who are asked to support many different development environments. 2

16

4.4 Installing the IBM Informix ODBC driver The IBM Informix ODBC Driver is installed as part of the

installation of the Informix Client Software Development Kit (CSDK). The CSDK has already been installed as part of the Informix installation on the VM image used in this exercise. For more information about how to install CSDK, refer to the Informix Information Center.

Set the following environment variables:

INFORMIXDIR: Full path to the directory where CSDK is installed. On the VM Image, it is same as the Informix Server Installation directory.

PATH: Make sure $INFORMIXDIR/bin is included in the $PATH

INFORMIXSQLHOSTS: Name of the SQLHOSTS file with full path.

Important: All of these environment variables have already been set for you.

Login to the VM image as the informix user and verify the current values of these variables using the following commands:

echo $INFORMIXDIR

echo $PATH

echo $INFORMIXSQLHOSTS

Copy the file $INFORMIXDIR/etc/odbcinst.ini to your home directory.

cp $INFORMIXDIR/etc/odbcinst.ini ~

Page 17: 2.4a Informix Application Development Survey Lab · This lab is especially useful for database administrators who are asked to support many different development environments. 2

17

Using a text editor such as vi, edit the ~/odbcinst.ini file:

In the section [IBM Informix ODBC Driver]:

i) Update the Driver and Setup lines to include the correct path

Driver=/opt/IBM/informix/lib/cli/iclit09b.so

Setup=/opt/IBM/informix/lib/cli/iclit09b.so

ii) Save and exit.

Copy the file $INFORMIXDIR/etc/odbc.ini to your home directory.

cp $INFORMIXDIR/etc/odbc.ini ~

Set the environment variable ODBCINI

export ODBCINI=$HOME/odbc.ini

Edit the $HOME/odbc.ini file.

i) Update the Driver field to /opt/IBM/informix/lib/cli/iclit09b.so

ii) Update the Database field to stores

iii) Update LogonID field to informix

iv) Update the pwd field to informix

v) Update the Servername field to demo_on

vi) Update the TRANSLATIONDLL field to /opt/IBM/informix/lib/esql/igo4a304.so

vii) Update the InstallDir field to /opt/IBM/informix/

Page 18: 2.4a Informix Application Development Survey Lab · This lab is especially useful for database administrators who are asked to support many different development environments. 2

18

vii) Save and exit.

Create or edit the $HOME/.netrc file to make an entry on the server for the informix user.

The format of the line that you need to add looks like the following:

machine <machinename> login informix password <password>

where:

machinename is host name or IP address of the server

password is the password of the informix user

Open the .netrc file available in the informix home directory and add the following line and save the file:

machine ids1150srvr login informix password informix

Edit the SQLHOSTS file and make an entry for the onsoctcp protocol for the database instance.

The format of the line that needs to be added is as follows:

<dbservername> onsoctcp <machinename> <portnumber>

where:

dbservername is the name of the Informix server.

machinename is the name or IP address of the host

portnumber is the number of the port..

Note: The following entry has already made for you in the $INFORMIXDIR/etc/sqlhosts.demos file. You do NOT have to make any modifications to the sqlhosts file.

demo_on onsoctcp *localhost 9088

Page 19: 2.4a Informix Application Development Survey Lab · This lab is especially useful for database administrators who are asked to support many different development environments. 2

19

Set the environment variable LD_LIBRARY_PATH. Enter the following command at the command prompt.

export LD_LIBRARY_PATH=$INFORMIXDIR/lib:$INFORMIXDIR/lib/cli:$INFORMIXDIR/lib/esql

You have now completed the basic installation and configuration of the Informix ODBC driver.

4.5 Running a sample C program to check the connectivity

Locate and examine the catalog.c sample program. This program retrieves information from the system catalogs.

cd $INFORMIXDIR/demo/cli/

cat catalog.c

Compile the program

make catalog

Execute the program.

./catalog Infdrv1

Note: Infdrv1 is the DSN name from the $ODBCINI file.

Page 20: 2.4a Informix Application Development Survey Lab · This lab is especially useful for database administrators who are asked to support many different development environments. 2

20

5. Programming with Informix ESQL/C

5.1 What is Informix ESQL/C? ESQL/C is an SQL application programming interface (API) that enables you to embed Structured Query Language (SQL) statements directly into a C program. The ESQL/C preprocessor, which the esql command invokes, converts each SQL statement and all Informix-specific code to C.

5.2 How can you create an ESQL/C program? You create an Informix ESQL/C program using the following steps:

Embed Informix ESQL/C statements in a C-language source program that perform the following tasks:

o Define host variables to store data for transfer between the Informix ESQL/C program and the database server.

o Access the database server through SQL statements.

o Provide directives for the Informix ESQL/C preprocessor and the C compiler.

Preprocess the Informix ESQL/C source file with the esql command to create a C-language source file and invoke the C compiler.

As necessary, correct errors reported by the preprocessor and the compiler and repeat step 2.

Using the esql command, link the compiled object code into one or more executable files.

An Informix ESQL/C source file may contain the following types of statements:

Preprocessor directives

Informix ESQL/C preprocessor directives are used to create simple macro definitions, include Informix ESQL/C files, and perform conditional Informix ESQL/C compilation.

Page 21: 2.4a Informix Application Development Survey Lab · This lab is especially useful for database administrators who are asked to support many different development environments. 2

21

C preprocessor directives are used to create macro definitions, include system and C source files, and perform conditional C compilation.

Language statements

Informix ESQL/C host variable definitions store data for transfer between the Informix ESQL/C program and the database server.

Embedded SQL statements communicate with the database server.

C language statements provide program logic.

5.3 Installing the IBM Informix ESQL/C Driver The IBM Informix ESQL/C driver is installed as part of the

installation of the Informix Client SDK (CSDK). CSDK is already installed on the VM image used in this lab. For more information about installing the CSDK, refer to the Informix Information Center.

Set the following environment variables:

INFORMIXDIR: Full path to the directory where CSDK is installed. On the VM Image it is same as the Informix server installation directory.

PATH: Make sure $INFORMIXDIR/bin is included in the $PATH

INFORMIXSQLHOSTS: Name of the SQLHOSTS file with full path.

We have already set all these environment variables for you. You can login to VM Image as the informix user and verify the current values of these variables using the following commands:

echo $INFORMIXDIR

echo $PATH

echo $INFORMIXSQLHOSTS

Page 22: 2.4a Informix Application Development Survey Lab · This lab is especially useful for database administrators who are asked to support many different development environments. 2

22

Create or edit the $HOME/.netrc file to make an entry on the server for the informix user.

The format of the line that you need to add looks like the following:

machine <machinename> login informix password <password>

where:

machinename is host name or IP address of the server

password is the password of the informix user

Open the .netrc file in the informix user’s home directory, add the following line, and then save the file.

machine ids1150srvr login informix password informix

Edit the SQLHOSTS file and make an entry for the onsoctcp protocol for the database instance.

The format of the line that needs to be added is as following:

<dbservername> onsoctcp <machinename> <portnumber>

where:

dbservername is the name of the Informix Server.

machinename is the name or IP address of the host

portnumber is the number of the port. An entry in /etc/services file.

Note: The following entry has already made for you in the $INFORMIXDIR/etc/sqlhosts.demos file. You do NOT have to make any modifications to the sqlhosts file.

demo_on onsoctcp *localhost 9088

Page 23: 2.4a Informix Application Development Survey Lab · This lab is especially useful for database administrators who are asked to support many different development environments. 2

23

Set the environment variable LD_LIBRARY_PATH

Enter the following command at the command prompt.

export LD_LIBRARY_PATH=$INFORMIXDIR/lib:$INFORMIXDIR/lib/cli:$INFORMIXDIR/lib/esql

We are done with the basic installation and configuration of the Informix ODBC driver.

5.4 Running a Sample ESQL/C Program to Test the Connectivity There are plenty of demo programs in the /opt/IBM/informix/demo/esqlc directory on the VM image.

Open the demo1.ec program in a text editor and change the name of the database to stores:

EXEC SQL connect to ‘stores’;

Can you figure out what this simple program does?

Compile the demo1.ec program and create an executable file:

esql demo1.ec -o demo1

Run the demo1 executable file that is created in the previous step:

./demo1

If the program is executed successfully, you will see all output rows displayed on the screen.

Page 24: 2.4a Informix Application Development Survey Lab · This lab is especially useful for database administrators who are asked to support many different development environments. 2

24

6. Configuring PHP Environment for Informix Databases

6.1 What is PHP? PHP is one of the world's most popular programming languages for building dynamic data-driven Web applications. The PHP code can be a standalone program as well as embedded inside HTML (Hypertext Markup Language) or XHTML (Extensible Hypertext Markup Language).

6.2 Informix interfaces for PHP Since PHP Version 3, Informix databases have served PHP client applications via the Informix connectivity software (Informix CSDK or Informix Connect). PHP applications could connect to the Informix database server using either the native embedded SQL interface or with the invocation of an ODBC library using the CLI (call level interface).

The following are the three most popular PHP APIs for Informix:

PDO

PDO Core is written in C for increased performance

Simple to learn ( Only 2 classes )

o PDO – Connection

o PDOStatement – Statement

Page 25: 2.4a Informix Application Development Survey Lab · This lab is especially useful for database administrators who are asked to support many different development environments. 2

25

PDO_INFORMIX

A PDO based extension for Informix

Written in C entirely by IBMers

Supported on PHP 5.1 and greater

Requirements:

o The Informix Client Software Development Kit (CSDK)

Available at: pecl.php.net/package/PDO_INFORMIX

PDO_IBM

A PDO based extension for IBM data servers

Written in C entirely by IBMers

Common PHP driver using the DRDA protocol, supporting Informix, DB2, Apache Derby.

Supported on PHP 5.1 and greater

Requirements:

o IBM Data Server Client for compilation/runtime

o DRDA configuration

Available at: pecl.php.net/package/PDO_IBM

Page 26: 2.4a Informix Application Development Survey Lab · This lab is especially useful for database administrators who are asked to support many different development environments. 2

26

6.3 Setting up the PHP application environment for Informix Important: For step-by-step information about installing, configuring, and testing a Linux, Apache, Informix, and PHP server, refer to the following article on the developerWorks Web site:

www.ibm.com/developerworks/db2/library/techarticle/dm-0606bombardier

This section provides an overview of the steps involved in manually setting up a PHP application development environment for Informix.

Important: All these steps have already performed on the VM Image. Also note that a PHP environment is set up if you use the OpenAdmin Tool!

Page 27: 2.4a Informix Application Development Survey Lab · This lab is especially useful for database administrators who are asked to support many different development environments. 2

27

A prerequisite for setting up the PHP environment is the setup of the Informix Server and CSDK.

Download and unpack the source code for the Apache HTTP Server, PHP, and Informix PHP Data Objects (PDO) driver.

Install and configure Apache HTTP Server

o The steps below outline how to install Apache with support for dynamically loaded modules:

(This assumes that the Apache source files are stored at: /usr/local/src/httpd-2.2.0)

cd /usr/local/src/httpd-2.2.0

./configure \

--prefix=/usr/local/apache \

--enable-shared=max \

--enable-module=rewrite \

--enable-module=so

make

make install

Install and configure PHP

A PHP installation requiers :

o An ANSI C compiler

o flex: Version 2.5.4

o bison: 1.28, 1.35, or 1.75

o A web server

o Any module-specific components

o Building PHP extensions on UNIX requires the phpize utility

o PHP 4 is not object oriented and doesn’t support PDO

Page 28: 2.4a Informix Application Development Survey Lab · This lab is especially useful for database administrators who are asked to support many different development environments. 2

28

Most Linux distributions come with PHP already installed. Manual compilation from source requires an ANSI C compiler.

buildconf force

./configure (--help)

make

make install

Installation of PDO_INFORMIX / PDO_IBM

There are two options here:

o Build with the PHP source

o Build stand alone

phpize (inside the extension source directory)

./configure –with-pdo-ibm=/home/db2inst1/sqllib

./configure –with-pdo-informix=/opt/informix

make

make install

Installation Debugging

o Check to make sure the IBM Data Server client and Informix CSDK is installed correctly.

o Make sure that the buildconf utility is run after copying the source directory to the ext directory.

o Make sure the options in the configure script are correct.

o Make sure the PHP version and extension version are the same.

o Make sure the PHP release/debug type are the same as the extensions.

o Make sure the correct php.ini file is being loaded.

Page 29: 2.4a Informix Application Development Survey Lab · This lab is especially useful for database administrators who are asked to support many different development environments. 2

29

6.4 Running a sample program to check the PHP configuration

In a text editor of your choice, enter and save the following three lines of code in a file called phpinfo.php in the /home/informix/scripts/php directory:

<?php

phpinfo();

?>

In the terminal windows set the paths for the php interpreter and the necessary libraries:

export PATH=$PATH:/opt/IBM/OpenAdmin/PHP_5.2.4/bin

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/IBM/OpenAdmin/PHP_5.2.4/lib

Open a terminal window, and run the program with the following command

php /home/informix/scripts/php/phpinfo.php

The About program will display the PHP configuration details on the screen. Examine the output.

6.5 Running a sample PHP program to test the Informix Database Connectivity

There is a sample PHP program called connect2IDS.php available in the /home/informix/scripts/php directory.

Run the program using the following command.

php -c /opt/IBM/OpenAdmin/PHP_5.2.4/lib/php.ini connect2IDS.php

If you are interested, open the file in a text editor and examine the code to see how it works.

Page 30: 2.4a Informix Application Development Survey Lab · This lab is especially useful for database administrators who are asked to support many different development environments. 2

30

This concludes the lab. If you have completed all the exercises and have extra time, feel free to continue exploring with the utilities/functionality described here. Otherwise, you can close the open any open windows.

Page 31: 2.4a Informix Application Development Survey Lab · This lab is especially useful for database administrators who are asked to support many different development environments. 2

31

© Copyright IBM Corporation 2010 All Rights Reserved. IBM Canada 8200 Warden Avenue Markham, ON L6G 1C7 Canada Printed in Canada 01/2010 IBM, IBM (logo), and Informix are trademarks or registered trademarks of International Business Machines Corporation in the United States, other countries, or both. Linux is a trademark of Linus Torvalds in the United States, other countries, or both UNIX is a registered trademark of The Open Group in the United States, other countries, or both Windows is a trademark of Microsoft Corporation in the United States, other countries, or both. Other company, product, or service names may be trademarks or service marks of others. References in this publication to IBM products or services do not imply that IBM intends to make them available in all countries in which IBM operates. The following paragraph does not apply to the United Kingdom or any other country where such provisions are inconsistent with local law: INTERNATIONAL BUSINESS MACHINES CORPORATION PROVIDES THIS PUBLICATION "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Some states do not allow disclaimer of express or implied warranties in certain transactions, therefore, this statement may not apply to you. This information could include technical inaccuracies or typographical errors. Changes are periodically made to the information herein; these changes will be incorporated in new editions of the publication. IBM may make improvements and/or changes in the product(s) and/or the program(s) described in this publication at any time without notice. Any performance data contained herein was determined in a controlled environment. Therefore, the results obtained in other operating environments may vary significantly. Some measurements may have been made on development-level systems and there is no guarantee that these measurements will be the same on generally available systems. Furthermore, some measurement may have been estimated through extrapolation. Actual results may vary. Users of this document should verify the applicable data for their specific environment.

Information concerning non-IBM products was obtained from the suppliers of those products, their published announcements or other publicly available sources. IBM has not tested those products and cannot confirm the accuracy of performance, compatibility or any other claims related to non-IBM products. Questions on the capabilities of non-IBM products should be addressed to the suppliers of those products. The information in this publication is provided AS IS without warranty. Such information was obtained from publicly available sources, is current as of January 2010, and is subject to change. Any performance data included in the paper was obtained in the specific operating environment and is provided as an illustration. Performance in other operating environments may vary. More specific information about the capabilities of products described should be obtained from the suppliers of those products.