# HOWTO: PHP Informix client support

## drsound

I was just asked to add Informix support to mod_php running on a Gentoo Linux server (x86): it should be used to develop a PHP application accessing an Informix server running on a Sco Unix. I was completely new to Informix, so I looked for info on the Internet and I got some connection parameters from existing ODBC connections on Windows workstations. In particular I copied from ODBC parameters (without further investigation) the "onsoctcp" communication protocol (it looks like there are several communication protocols available) and the "firm_name_01" parameter (should be the "database server name": beware it's not the DNS name of the host running the Informix server! Probably it's assigned when you install the Informix server). Here are the steps I needed, hope it helps:

0) Download the Informix client from IBM website: I got "Informix Client SDK V2.81.UC3 32 bit for Linux on Intel" (clientsdk.2.81.UC3.LINUX-I32.tar).

1) groupadd informix ; useradd -g informix -d /dev/null informix

2) mkdir /opt/informix

3) Move clientsdk.2.81.UC3.LINUX-I32.tar to /opt/informix and untar it.

4) You will need cpio, so if you haven't do emerge cpio.

5) Unpack csdk.cpi using cpio -idumB <csdk.cpi (notice the absence of the "c" flag in cpio parameters, it would not work otherwise).

6) Within the unpacked files there will be 3 or 4 scripts (installclientsdk, etc. can't remember the names now): modify them searching for "cpio" and removing all "c" flag references (see previous step).

7) Run installclientsdk.

8) Create the file /etc/env.d/99informix containing the following lines:

INFORMIXDIR=/opt/informix

PATH=/opt/informix/bin

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

INFORMIXSERVER=firm_name_01

LDPATH=/opt/informix/lib:/opt/informix/lib/esql:/opt/informix/lib/cli:/opt/informix/lib/client

NB: substitute "firm_name_01" with your "database server name".

9) env-update ; source /etc/profile

10) Edit /opt/informix/etc/sqlhosts adding the parameters needed to establish a connection to the Informix server. In my case they were "firm_name_01 onsoctcp 192.168.0.1 1526".

Field 1 is the name of the database server (the same used in step number 8), field 2 is the communication protocol (often referred to as "nettype" in Informix's documentation), field 3 is the DNS name or IP address, field 4 is the service name or port number.

11) If you want you can test your connection trying some of the demos in /opt/informix/demo. I wasn't so successful in this: I suppose you have to create some db/tables/permissions on the server to let the demos work. Anyway if you get some error code you can use /opt/informix/bin/finderr to get a textual description.

12) Add the "informix" use flag in /etc/make.conf and emerge mod_php.

13) Add these lines to /etc/apache2/conf/apache2.conf:

SetEnv INFORMIXDIR /opt/informix

SetEnv ODBCINI /usr/local/etc/odbc.ini

SetEnv INFORMIXSERVER firm_name_01

14) The /etc/init.d/apache2 scripts clears the environment (env -i) before starting the Apache daemon, but we need to preserve some variables if we want mod_php to work, so modify the script this way (the original lines are commented):

#env -i PATH=$PATH /sbin/start-stop-daemon --quiet \

#   --start --startas /usr/sbin/apache2 \

#   --pidfile ${PIDFILE} -- -k start ${APACHE2_OPTS}

env -i \

    PATH=$PATH:/opt/informix/bin \

    INFORMIXSERVER=firm_name_01 \

    INFORMIXDIR=/opt/informix \

    ODBCINI=/opt/informix/etc/odbc.ini \

    /sbin/start-stop-daemon --quiet \

    --start --startas /usr/sbin/apache2 \

    --pidfile ${PIDFILE} -- -k start ${APACHE2_OPTS}

NB: if you use the statement VARIABLE=$VARIABLE (as for PATH) it will not work when Apache is started at boot time, probably because Apache is started before the variables in /etc/profile are added to the environment.

15) /etc/init.d/apache2 restart

16) Execute a phpinfo() to check if PHP sees the environment variables: looking in the "PHP Variables" section you should see the values you added in /etc/apache2/conf/apache2.conf as _SERVER variables (example _SERVER["INFORMIXDIR"]="/opt/informix") and the ones you added in /etc/init.d/apache2 as _ENV variables (example _ENV["INFORMIXDIR"]="/opt/informix").Last edited by drsound on Sat Feb 05, 2005 3:25 pm; edited 1 time in total

----------

## Niosop

My current project requires interfacing with an HP-UX Informix DB.  I was dreading setting this up, as all the information I had gathered so far was fragmentary.  Then I found this post (I should have known it would be on gentoo forums, everything is) and it worked like a charm.

Thanks so much for posting this, I'm sure it saved me hours (or more likely, days) of pounding my head trying to get it to work.

Very appreciatively,

Niosop

P.S.  I especially like the cpio arguments -idumB.  Was that intentional on your part?

[EDIT] You may also want to move step 7 to after step 9 as the installclientsdk script wants the env vars set.

----------

## queru

Same for 2.90.UC3?

Thanks.

----------

## queru

This works for me until yesterday. In the today upgrade of apache2, changes are made by Gentoo in the location of the files. I adjust everything, re-emerge the mod_php, and all that I get is:

```
ifx_connect(): E [SQLSTATE=IX 001 SQLCODE=-1829]
```

I follow every step a hundred of times. I'm totally lost.

Any idea, please?

----------

## queru

Ok, it works now.

Is really very very important to see the INFORMIX vars in the _ENV array in a phpinfo() page. I only can get this using this start function in /etc/init.d/apache2 bash script:

```

start() {

        checkconfig || return 1

        ebegin "Starting apache2"

        [ -f /var/log/apache2/ssl_scache ] && rm /var/log/apache2/ssl_scache

        [ -f /usr/lib/apache2/build/envvars ] && . /usr/lib/apache2/build/envvars

        env -i \

                PATH=$PATH:/opt/informix/bin \

                INFORMIXDIR=/opt/informix \

                ODBCINI=/opt/informix/etc/odbc.ini \

                INFORMIXSERVER=mazesc1_tcp \

                DBDATE=DMY4/ \

                CLIENT_LOCALE=en_US.819 \

                DB_LOCALE=en_US.819 \

                INFORMIXSQLHOSTS=/opt/informix/etc/sqlhosts \

                SQLIDEBUG=/tmp/ifx \

                /sbin/start-stop-daemon --quiet \

                --start --startas /usr/sbin/apache2 \

                --pidfile ${PIDFILE} -- -k start ${APACHE2_OPTS}

                #${APACHE2} ${APACHE2_OPTS} -k start

        eend $?

}

```

The _ENV array from the server:

```

 _ENV["PATH"]  [...]:/opt/informix/bin

 _ENV["INFORMIXDIR"]  /opt/informix

 _ENV["ODBCINI"]  /opt/informix/etc/odbc.ini

 _ENV["INFORMIXSERVER"]  mazesc1_tcp

 _ENV["DBDATE"]  DMY4/

 _ENV["CLIENT_LOCALE"]  en_US.819

 _ENV["DB_LOCALE"]  en_US.819

 _ENV["INFORMIXSQLHOSTS"]  /opt/informix/etc/sqlhosts

 _ENV["SQLIDEBUG"]  /tmp/ifx

```

The Informix Client SDK it's a bullshit piece of code.[/b]

----------

## midan

in /etc/conf.d/apache2

# Environment variables to keep

# All environment variables are cleared from apache

# Use this to preserve some of them

# NOTE!!! It's very important that this contains PATH

# Also, it will fail if the _value_ of any of these variables contains a space

KEEPENV="PATH INFORMIXDIR INFORMIXSERVER"

and there is no need to modify /etc/init.d/apache2 bash script:

----------

## 5Ball

Since there is only one INFORMIXSERVER environment variable set in the Apache configuration file, is it not possible to connect to more than one database server?Last edited by 5Ball on Mon Oct 31, 2005 10:44 pm; edited 1 time in total

----------

## Niosop

After hours of pounding my head, I've finally got PHP5+Informix client working on a new AMD64 server.  I didn't document everything I did, because I didn't really think I'd get it to work, but here are some hints for anyone trying to do the same.  If you attempt it, please document it and post it here.

-Download the 64 bit Linux Informix client SDK from IBM.

-Do everything in the original post

-Using rpm and cpio, run all the install programs you can.  I never got all the way through w/o errors, but evidentally enough was finished to get it to work.

-Comment out the informix entry in /usr/portage/profiles/default-linux/amd64/use.mask

-Start a dev-lang/php emerge, but at some point your going to have to Control-Z and fix the file described in http://lists.alioth.debian.org/pipermail/pkg-php-maint/2005-September/000194.html

-Resume the emerge w/ fg.

After that, it should work ok.

The configure script and/or Makefile should really be fixed instead of the ugly pause compiling/fix file/resume hack above, but that's for someone wiser than me.

Hope this helps someone.

----------

## asommer

Hello,

I found this thread and thought FREAKIN Awesome I need Informix on Gentoo...

Then I realized I'm running an AMD64...heh

Anyway, I finally got the informix client-sdk to run on Gentoo.  I did it in a sort of round about way:

 *Quote:*   

> 
> 
> 1.  I downloaded the Informix Client Software Development Kit 2.90.FC4: http://www14.software.ibm.com/webapp/download/preconfig.jsp?id=2006-01-26+07%3A28%3A52.181415R&S_TACT=104CBW71&S_CMP=
> 
> *** I couldn't find the UC file in for 64.  ***
> ...

 

I'm not sure how good of an idea installing 2 package managers is, but I figure if the only rpms I ever install are from 3rd party odd ball places it shouldn't hurt anything.  I was truly surprised that rpm was even in portage!  Definitely cool that it was.

Maybe this will help someone in the future...or if you have a better way to install the clientsdk on amd64 let me know.

----------

## mafonso

Hello, list

I need to install php with informix support, but seems that informix is no longer supported in portage (read somewhere that the informix use flag was removed...)

Do I need to do it all 'by hand'? (downloading source from php site, configure, make and make install...)

The machine is an AMD64

thanks in advance.

btw, merry christmas  :Wink: 

----------

## mafonso

Hi

I did this (after installed the IBM client sdk and setted all the environment variables):

```

# emerge php

# emerge PEAR-PEAR

# pecl install --alldeps pdo_informix

```

Then I edited php.ini and wrote this:

```

extension=pdo.so

```

I created a php script with an ifxconnect() evocation into it, just for a test, but then:

```

# php -f test.php

Fatal error: Call to undefined function ifx_connect()...

```

Something is missing...

Any ideas?

----------

## mafonso

hum... I guess I can't use ifx_* anymore...

the sintax from php v5.2.1 on is something like:

```

<?php

$dbh = new PDO('informix:host=somehost;dbname=somedbname', $user, $pass);

?>

```

Is there any way of putting ifx_* back to work?

Configuring php like ./configure --with-informix=... doesn't work

I guess the only solution is install 5.2.0 or earlier...

----------

## mafonso

I found this.

I successfully compiled and installed informix.so from php 5.2.0.

ifx_connect apparently works, but php segfaults with an ifx_query  :Sad: 

The problem may be something about informix configuration, or the module informix.so just doesn't work

I'm also trying to connect with pdo like this:

```

try {

   $dbh = new PDO('informix:host=somehost;database=somedb', 'someusr', 'somepass');

   foreach ($dbh->query('SELECT * from cliente') as $row) {

      print_r($row);

   }

   $dbh = null;

} catch (PDOException $e) {

   print "Error!: " . $e->getMessage() . "<br/>";

   die();

}

```

but the result is:

```

Error!: SQLSTATE=HY000, SQLDriverConnect: -11060 [Informix][Informix ODBC Driver]Unspecified System Error = -11060.

```

I'll just keep on trying.

Any ideas are welcome.

----------

