2010/01/26

informix database using PHP

In a project, I need to write a php code to talk to informix database, which I have not done before.

First, you need PHP Informix Module, here is an guide, http://www.ibm.com/developerworks/data/library/techarticle/dm-0606bombardier/

Fortunately, the server I am working on has already installed this module, so I just wrote a simple test script as the following,

<?php
$conn_id = ifx_connect ("mydb@ol_srv1", "user", "pass");
?>

This code snippet is from PHP Manual, which is actually not a good for test. because if there is some error in ifx_connect, you will not see any error message. I found a better one from PhpDig.net, http://www.phpdig.net/ref/rn30re552.html

if (!$conn = @ifx_connect( "stores7@demo_se", "testuser", "password" )) {
   die( sprintf( "Connection error: %s %s", ifx_error(), ifx_errormsg() ) );
}

I experienced the following error at the beginning,

Connection error: E [SQLSTATE=IX 001  SQLCODE=-1829] Unable to load locale categories.

The guy from IBM had an explanation http://www.iiug.org/forums/ids/index.cgi/noframes/read/3333

OK, some environment parameters missing, $INFORMIXDIR, after fixing this one, I got another one missing:

Connection error: E [SQLSTATE=IX 000  SQLCODE=-25560] Environment variable INFORMIXSERVER must be set.

Finally, fixed!