8
Antonio Musarra's Blog The ideal solution for a problem Blog: http://musarra.wordpress.com Company Portal: http://www.romcad.it Mail: [email protected] 09/03/10 1 This document is issued with license Creative Commons Attribution-NonCommercial-ShareAlike The ultimate guide of: Mac OS X Snow Leopard, Informix, PHP 5.3 & PDO 1. Introduction In my last article Mac OS X Snow Leopard: 11.5 + PHP Informix IDS 5.3 (Musarra, 2009) was explained how to install and configure IBM Informix IDS 11.5 shows also install the PHP module Informix (The PHP Group, 2010). In this article we will see how to complete successfully the installation of the PDO Informix Module (The PHP Group, 2010), but not only, we also see some practical example using the PDO Informix Module. The module is the PDO Informix driver that implements the PHP Data Object (PDO) (The PHP Group, 2010) that allows access from PHP to IBM Informix IDS database. 2. Requirements for installing the PDO Informix Module The installation of the module requires Informix Client SDK 2.81 (or higher) for short CSDK, installed on the same system of PHP (ie Mac OS X Snow Leopard). For more information on CSDK, including the same installation package, are available at the site IBM Informix Support Site 1 . Assume you have installed and configured on your machine Mac OS X Snow Leopard software IBM Informix IDS 11.5. Council to refer to the installation and configuration of IBM Informix IDS 11.5 to the official documentation available on the IBM Informix Online Transaction Processing (OLTP) 2 or Article Mac OS X Snow Leopard: Informix IDS 11.5 + PHP 5.3. The latest stable version of PDO Informix module we're going to install is version 1.2.6. 1 http://www-306.ibm.com/software/data/informix/tools/csdk/ 2 http://www-01.ibm.com/software/data/informix/?pgel=ibmhzn&cm_re=masthead-_-products-_-sw-informix

Mac OS X Snow Leopard & Informix 11.5 + PHP 5.3 + PDO

Embed Size (px)

DESCRIPTION

Description: In this article we will see how to complete successfully the installation of the PDO Informix Module (The PHP Group, 2010), but not only, we also see some practical example using the PDO Informix Module. The module is the PDO Informix driver that implements the PHP Data Object (PDO) (The PHP Group, 2010) that allows access from PHP to IBM Informix IDS database.

Citation preview

Page 1: Mac OS X Snow Leopard & Informix 11.5 + PHP 5.3 + PDO

Antonio Musarra's Blog

The ideal solution for a problem Blog: http://musarra.wordpress.com Company Portal: http://www.romcad.it Mail: [email protected]

09/03/10 1

This document is issued with license Creative Commons Attribution-NonCommercial-ShareAlike

The ultimate guide of: Mac OS X Snow Leopard, Informix, PHP 5.3 & PDO

1. Introduction

In my last article Mac OS X Snow Leopard: 11.5 + PHP Informix IDS 5.3 (Musarra, 2009) was explained how to install and configure IBM Informix IDS 11.5 shows also install the PHP module Informix (The PHP Group, 2010). In this article we will see how to complete successfully the installation of the PDO Informix Module (The PHP Group, 2010), but not only, we also see some practical example using the PDO Informix Module.

The module is the PDO Informix driver that implements the PHP Data Object (PDO) (The PHP Group, 2010) that allows access from PHP to IBM Informix IDS database.

2. Requirements for installing the PDO Informix Module

The installation of the module requires Informix Client SDK 2.81 (or higher) for short CSDK, installed on the same system of PHP (ie Mac OS X Snow Leopard). For more information on CSDK, including the same installation package, are available at the site IBM Informix Support Site1.

Assume you have installed and configured on your machine Mac OS X Snow Leopard software IBM Informix IDS 11.5. Council to refer to the installation and configuration of IBM Informix IDS 11.5 to the official documentation available on the IBM Informix Online Transaction Processing (OLTP)2 or Article Mac OS X Snow Leopard: Informix IDS 11.5 + PHP 5.3.

The latest stable version of PDO Informix module we're going to install is version 1.2.6.

1 http://www-306.ibm.com/software/data/informix/tools/csdk/ 2 http://www-01.ibm.com/software/data/informix/?pgel=ibmhzn&cm_re=masthead-_-products-_-sw-informix

Page 2: Mac OS X Snow Leopard & Informix 11.5 + PHP 5.3 + PDO

Antonio Musarra's Blog

The ideal solution for a problem Blog: http://musarra.wordpress.com Company Portal: http://www.romcad.it Mail: [email protected]

09/03/10 2

This document is issued with license Creative Commons Attribution-NonCommercial-ShareAlike

3. Make and installing the Informix PDO Module

The version of PHP installed as standard on Mac OS Snow Leopard is version 5.3 (check with the command php -v run from your terminal) complete support PDO.

You can verify that the support PDO is enabled with the command php -i | grep-E "PDO", giving an output similar to the one shown in Listing 1 shows that the approval of the form PDO and PDO drivers installed (when PDO drivers => mysql, sqlite, sqlite2).

PDO

PDO support => enabled

PDO drivers => mysql, sqlite, sqlite2

PDO Driver for MySQL => enabled

PDO Driver for SQLite 3.x => enabled

Listing 1 Output of the command to verify the PDO module

Installation of PECL modules (The PHP Group, 2009) occurs in the usual way, using the command sudo pecl install PDO_Informix. The only use prudence in the use of the command is to specify the option --nodeps, which is necessary to skip the dependency form PDO, that "strangely" not as a package is installed via PECL. The command for installing the complete PECL module becomes:

sudo pecl install --nodeps PDO_Informix

In Listing 2 shows an excerpt of the output produced by the process of installing the PDO Informix module. The build process requires knowledge of the module installation path CSDK usually check the installation path by reading the environment variable INFORMIXDIR (configured during installation of IBM Informix IDS 11.5), if the environment variable does not were available or had the wrong value assigned to the variable, the build process requires the installation path CSDK, in my case the path coincides with INFORMIXDIR.

amusarra-mobile:~ amusarra$ sudo pecl install --nodeps --soft PDO_Informix

downloading PDO_INFORMIX-1.2.6.tgz ...

Starting to download PDO_INFORMIX-1.2.6.tgz (65,676 bytes)

PHP Api Version: 20090626

Zend Module Api No: 20090626

Zend Extension Api No: 220090626

Informix Client SDK location? : /opt/IBM/Informix

Build process completed successfully

Installing '/usr/lib/php/extensions/no-debug-non-zts-20090626/pdo_informix.so'

install ok: channel://pear.php.net/PDO_INFORMIX-1.2.6

Listing 2 Part of the output of the process of installing the PDO Informix module

Page 3: Mac OS X Snow Leopard & Informix 11.5 + PHP 5.3 + PDO

Antonio Musarra's Blog

The ideal solution for a problem Blog: http://musarra.wordpress.com Company Portal: http://www.romcad.it Mail: [email protected]

09/03/10 3

This document is issued with license Creative Commons Attribution-NonCommercial-ShareAlike

PDO Informix module was installed in the directory that contains all extensions of PHP (in / usr/lib/php/extensions/no-debug-non-zts-20090626).

Now that the installation was completed, one must proceed with the activation of the PDO Informix module adding the appropriate line to the configuration file of PHP, then edit the file / etc / php.ini putting the line:

extension=pdo_informix.so

You can verify the correct installation and configuration of the module by running the command php -i | grep-E "PDO | pdo_informix", in Listing 3 shows the output of the previous command.

PDO

PDO support => enabled

PDO drivers => mysql, sqlite, sqlite2, Informix

pdo_informix

pdo_informix support => enabled

PDO Driver for MySQL => enabled

PDO Driver for SQLite 3.x => enabled

Listing 3 Verify installation and configuration PDO Informix module

4. Configuration ODBC Informix

The PDO Informix module requires the correct configuration of ODBC Driver Informix. Installing IBM Informix IDS provides that the ODBC configuration file (Wikipedia, 2010) sample are installed inside the etc directory to INFORMIXDIR, the files are:

/opt/IBM/informix/etc/odbc.ini /opt/IBM/informix/etc/odbcinst.ini

The ODBC configuration file must be reviewed on the basis of its installation and needs. In Listing 4 and Listing 5 shows both the files appropriately modified.

Page 4: Mac OS X Snow Leopard & Informix 11.5 + PHP 5.3 + PDO

Antonio Musarra's Blog

The ideal solution for a problem Blog: http://musarra.wordpress.com Company Portal: http://www.romcad.it Mail: [email protected]

09/03/10 4

This document is issued with license Creative Commons Attribution-NonCommercial-ShareAlike

[ODBC Data Sources]

Infdrv1=IBM INFORMIX ODBC DRIVER

;

; Define ODBC Database Driver's Below - Driver Configuration Section

;

[Infdrv1]

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

Description=IBM INFORMIX ODBC DRIVER

Database=stores_demo

LogonID=odbc

pwd=odbc

Servername=amusarra_ifx Listing 4 Part of the odbc.ini rivisto.

[ODBC Drivers]

IBM INFORMIX ODBC DRIVER=Installed

[IBM INFORMIX ODBC DRIVER]

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

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

APILevel=1

ConnectFunctions=YYY

DriverODBCVer=03.51

FileUsage=0

SQLLevel=1

smProcessPerConnect=Y Listing 5 Parte del file odbcinst.ini reviewed.

After changing the configuration files ODBC you must set the environment variable ODBCINI, the value to assign is INFORMIXDIR /etc/odbc.ini.

export ODBCINI=/opt/IBM/informix/etc/odbc.ini

For more information about ODBC Informix consult the official documentation available at: http://publib.boulder.ibm.com/infocenter/idshelp/v115/topic/com.ibm.odbc.doc/odbc.htm

Page 5: Mac OS X Snow Leopard & Informix 11.5 + PHP 5.3 + PDO

Antonio Musarra's Blog

The ideal solution for a problem Blog: http://musarra.wordpress.com Company Portal: http://www.romcad.it Mail: [email protected]

09/03/10 5

This document is issued with license Creative Commons Attribution-NonCommercial-ShareAlike

5. Test PDO Informix Module

At this point, you need only write a simple PHP script to test the proper operation of the module PDO Informix. To do this test you can take advantage stores_demo as data base on which to run our tests. In Listing 6 shows a sample script that performs a connection and a subsequent query to the database as indicated on the IBM Informix ODBC configuration seen in the previous paragraph.

The PDO Informix Module connects to the IBM Informix database using a connection string to the compliant structure of the Data Source Name (DSN) (Wikipedia, 2009) based on Informix ODBC DSN Name.

#!/usr/bin/php

<?php

try {

$db = new PDO("informix:DSN=Infdrv1", "", "");

$stmt = $db->prepare('SELECT CAT_ADVERT, CAT_DESCR, CAT_PICTURE FROM CATALOG WHERE CATALOG_NUM =

?');

$stmt->execute(array('10073'));

$stmt->bindColumn(1, $Advert, PDO::PARAM_STR, 256);

$stmt->bindColumn(2, $Descr, PDO::PARAM_STR, 512);

$stmt->bindColumn(3, $Pic, PDO::PARAM_LOB);

$stmt->fetch(PDO::FETCH_BOUND);

echo "Advert: $Advert\n";

echo "Catalog Desc: $Descr\n";

$db = null;

} catch (PDOException $e) {

print "Error!: " . $e->getMessage() . "\n";

die();

}

?>

Listing 6 PHP script for test PDO Informix module

In Table 1 are shown a number of possible mistakes that you may encounter when running the script shown in Listing 6. Is there a command that returns the IBM Informix error description on the basis of the error code received, the command is called finderr. In Listing 7, the example of using the command with the error code -908.

Page 6: Mac OS X Snow Leopard & Informix 11.5 + PHP 5.3 + PDO

Antonio Musarra's Blog

The ideal solution for a problem Blog: http://musarra.wordpress.com Company Portal: http://www.romcad.it Mail: [email protected]

09/03/10 6

This document is issued with license Creative Commons Attribution-NonCommercial-ShareAlike

Tabella 1 Possible execution errors

Error Error!: SQLSTATE=IM002, SQLDriverConnect: -11041 [Informix][Informix ODBC Driver]Data source name not found and no default driver specified.

Description This type of error may occur because the DSN name specified in the connection string is not in the odbc.ini configuration file, it is also possible that the error is due to incorrect use of the environment variable ODBCINST.

Solution A) Check the configuration file odbc.ini and possible correction of the PHP script file or the same odbc.ini;

B) Verify that the environment variable is set correctly ODBCINI (use the command echo $ODBCINI). Refer to the relevant section on configuring ODBC Informix.

Error Error!: SQLSTATE=00000, SQLDriverConnect: 0

[iODBC][Driver Manager]dlopen(/opt/IBM/informix/cli/iclit09b.dylib, 6): image not found

Description Error that occurs when the ODBC driver is not loaded correctly, in this case the error is due to incorrect path of the driver.

Solution Change the path of the driver on the ODBC odbc.ini configuration file. In this case the correct path is: /opt/IBM/informix/lib/cli/iclit09b.dylib.

Error Error!: SQLSTATE=08004, SQLDriverConnect: -908

[Informix][Informix ODBC Driver][Informix]Attempt to connect to database server (amusarra_ifx) failed.

Description The PHP script cannot connect to the server specified on the IBM Informix ODBC configuration. The problem may be due to network or simply the fact that the IBM Informix instance is not active.

Solution Assuming that the IBM Informix instance is not active, we perform a check and later start the instance. Use the command onstat- IBM Informix to verify that both the state and online command oninit to bring the database online.

Page 7: Mac OS X Snow Leopard & Informix 11.5 + PHP 5.3 + PDO

Antonio Musarra's Blog

The ideal solution for a problem Blog: http://musarra.wordpress.com Company Portal: http://www.romcad.it Mail: [email protected]

09/03/10 7

This document is issued with license Creative Commons Attribution-NonCommercial-ShareAlike

amusarra-mobile:MacOSXSnowLeopard_InformixIDS11.5_PDO amusarra$ finderr -908

-908 Attempt to connect to database server (servername) failed.

The program or application is trying to access another database server

but has failed. Note the server name in the current statement.

The desired database server is unavailable, or the network is down or

is congested. Ask your DBA and system administrator to verify that the

server and network are operational. If the network is congested, use

the environment variables INFORMIXCONTIME and INFORMIXCONRETRY to tune

connection timing. For information on setting these environment variables,

see the IBM Informix Guide to SQL: Reference.

This message appears in Version 6.0 and later versions.

Listing 7 Command output finderr for error -908

Page 8: Mac OS X Snow Leopard & Informix 11.5 + PHP 5.3 + PDO

Antonio Musarra's Blog

The ideal solution for a problem Blog: http://musarra.wordpress.com Company Portal: http://www.romcad.it Mail: [email protected]

09/03/10 8

This document is issued with license Creative Commons Attribution-NonCommercial-ShareAlike

Bibliography

Musarra, A. (2009, Novembre 23). Mac OS X Snow Leopard: Informix IDS 11.5 + PHP 5.3. Tratto da IBM My developerWorks: https://www.ibm.com/developerworks/mydeveloperworks/blogs/amusarra/entry/mac_os_x_snow_leopard_informix_ids_11_5_php_5_31?lang=en

The PHP Group. (2009, Agosto 7). PECL :: The PHP Extension Community Library. Tratto da PECL :: The PHP Extension Community Library: http://pecl.php.net/

The PHP Group. (2010, Febbraio 26). PHP: Informix (PDO). Tratto da PHP: Hypertext Preprocessor: http://it.php.net/manual/en/ref.pdo-informix.php

The PHP Group. (2010, Febbraio 26). PHP: Informix Manual. Tratto da PHP: Hypertext Preprocessor: http://it.php.net/manual/en/book.ifx.php

The PHP Group. (2010, Febbraio 26). PHP: PDO Manual. Tratto da PHP: Hypertext Preprocessor: http://it.php.net/manual/en/book.pdo.php

Wikipedia. (2009, Novembre 29). Database Source Name - Wikipedia. Tratto da Database Source Name - Wikipedia: http://en.wikipedia.org/wiki/Database_Source_Name

Wikipedia. (2010, Gennaio 7). ODBC - Wikipedia. Tratto da Open Database Connectivity (ODBC): http://en.wikipedia.org/wiki/ODBC