Thursday, May 29, 2008

Project site for Informix dbo for cakephp 1.2

http://code.google.com/p/dboinformixdriver/

courtesy of jmomorales

Code is for Informix 7.3 but I run Informix 9.40 and its quite fine. Just implemented a fix for pagination.

Tuesday, May 20, 2008

Informix and CakePHP 1.2

Today, I tried some kick-ass stuff. Connecting an existing Informix database with cakePHP 1.2. First thing I tried is to use the adodb db wrapper which is built in cakephp. If you need to use adodb, you have to download it from here. Then you extract it and place it in app/vendor.

var $default = array(
'driver' => 'adodb',
'connect' => 'informix',
'persistent' => false,
'host' => 'myserver',
'port' => '9109',
'login' => 'informix',
'password' => 'mypass',
'database' => 'mydb',
'schema' => '',
'prefix' => '',
'encoding' => ''
);

Somehow, this configuration setting works and cakephp's default homepage now shows that it can connect to a database. However, when I try to create a model, and scaffold a controller, it tells me that the table for the model cannot be found.

So then I scour the cyberspace again, looking for the possibility of the existence of a pdo_informix.php file, and I found it hidden in the cakephp google groups, written by Marcelo of San Luis, Argentina. The link can be found here. You need to change the code a little, to set the INFORMIXSERVER environment and get rid of the error

SQLSTATE=IX 000 SQLCODE=-25596


...
function connect()
{
$config = $this->config;
$connect = $config['connect'];
$this->connected = false;

$host = $config['database'] . '@' . $config['host'];
$argHostname = $config['host'];
if ($argHostname) putenv("INFORMIXSERVER=$argHostname");
putenv("INFORMIXSERVER=".trim($argHostname));
if ($config['persistent'])
{
$this->connection = ifx_pconnect($host, $config['login'], $config['password']);
}
else
{
$this->connection = $connect($host, $config['login'], $config['password']);
}

$this->connected = ($this->connection !== false);
return $this->connected;
}
...


Hopefully, the rest of the code can be recycled. I have not tested them yet.

Monday, May 19, 2008

Lunch at Karen's

5+1 people who ate at Karen's. The sixth is the photographer.
Now can you guess who the photographer is? And who's taking the photo now?... Hah Hah
Mmm... nice...
Mmm....not so nice...
Had sweet and sour fish with lots of onions (my favourite), black chicken soup and mixed vegetables. Actually, I should have started cooking the chicken as after an hour, the soup doesnt have much taste. The fish was ok, I guess. The vegetables needed some prawns.

Anyway, always room for improvement.

Sunday, May 18, 2008

Fishing trip

Feeling down 'cause you didn't get any fish?

This tent is amazingly easy to fix up!

Fishermen...

Fresh fish from the reservoir.

The same fish.

The same reservoir.
Fixing the line, it got tangled.
Fixing the fishing line. The line got tangled so many times it got cut to save time.This is what they tried to use to catch fish, without any live bait.
These kids caught some lobster or shellfish by just using a stick with fish meat. They actually caught a few.
Kids caught a few lobsters or shellfishes by just using a stick with fish meat.

I ate junk food while they fished.






Thursday, May 15, 2008

Informix meets Wampserver 2 Part 2

The most beautiful string in a PHP-Informix programmer's life:


$db = new PDO("informix:host=;service=;database=;
server=;protocol=onsoctcp;DB_LOCALE=en_US.8859-1", "username", "password");


PDO constructor: PDO("db:xxxx", "username", "password");

host_computername: the name of the server hosting informix, if unsure, check /etc/hosts

service_port: the port number used by the server, if unsure, check $INFORMIXDIR/etc/sqlhosts for the service name then go to /etc/services to find out the port number

db_name: name of the database you want to connect to, obviously...

server_name: name of the server, don't get confused with host. Yeah, you're already confused...

protocol: I really got no idea what this is, and what difference it makes, will post later when I find out more.

DB_LOCALE: Sets the locality, but I think its more useful in killing this error


'PDOException' with message 'SQLSTATE=HY000, SQLDriverConnect: -23197 [Informix][Informix ODBC Driver][Informix]Unspecified System Error = -23197.'


The username and password is the one you use to log in the linux host, so username must be informix.

I also adapted code copied from http://www.informix-zone.com/informix-script-dbapi#php
to test out the connection string.

<?php
# ------------------------------------
# open connection to database 'stores'
# ------------------------------------
try {
$dbh = new PDO("informix:host=example.com;service=1234;database=stores;
server=myserver;protocol=onsoctcp;DB_LOCALE=en_US.8859-1", "informix", "123456");
}
catch (exception $e) {
print $e;
}
# ----------------
# open transaction
# ----------------
$dbh->beginTransaction();

# --------------------------------------
# prepare and execute 'select' statement
# --------------------------------------
$sth1 = $dbh->prepare("select bank_code, bank_name from bank");
$sth1->execute();
# ---------------------
# fetch thru result set
# ---------------------
while( $row = $sth1->fetch() )
{
# --------
# show row
# --------
//echo "<pre>";
//print_r($row);
//echo "</pre>";
echo $row[BANK_CODE] . ' - ' . $row[BANK_NAME] . '<br/>';
}
$dbh = null;

?>

Tuesday, May 13, 2008

Informix meets wampserver 2

Ok, so here's the story. The easy part is getting the PDO_informix object turned on in Wampserver. You just need to click right click on the wampserver icon, go to PHP > PHP extensions > php_pdo_informix.

Then create a new php file, and type this:


<?php
$i=0;
try {
$db = new PDO(
"informix:host=it;service=1526;database=stores_demo;server=ol_it;
protocol=olsoctcp;EnableScrollableCursors=1;DB_LOCALE=EN_US.8859-1",
"informix",
"informix");
}
catch (PDOException $e) {
echo "Could not connect to Informix servr:\n" . $e->getMessage() . "\n";
}
?>

Source: http://www.ibmdatabasemag.com/showArticle.jhtml?articleID=191502698
On my system, the web browser will puke out an error:


Could not connect to Informix server: SQLSTATE=HY000, SQLDriverConnect: -23101 [Informix][Informix ODBC Driver][Informix]Unable to load locale categories.


which is eerily similar to the case where you try to use the iLogin demo that comes with the Informix installation.

Strange thing is if you tried Server Studio, you don't get the locale error.

The time now is 1715 and happily I write with a solution to my problem.
SOLUTION:

On WindowsXP, set the INFORMIXDIR and INFORMIXSERVER in Environment Variables. They should look like:


INFORMIXDIR = C:\Program Files\IBM\Informix\Connect
INFORMIXSERVER = ol_[computer name]


but should be a bit different for you if you installed Informix in a different folder.
See the screenshot below for my trophy. PHP connects to the demo database stores_demo. I did a simple "SELECT * FROM customer" query.



What else did I try but did not work?


SetEnv INFORMIXDIR C:\Program Files\Informix
SetEnv INFORMIXSERVER ol_it


I placed these two in httpd.conf and restarted the server. They did appear in Apache Environment but it is not what I need. I need it to appear in Environment.

The running ol_[computer name] batch file in Start Menu > Informix Dynamic Server 9.40 ol_[computer name]. It gives you the illusion that the environments are set, but aren't.

Some useful links for reference, http://www.ffnn.nl/pages/articles/linux/vmware-player-image-creation.php
to create empty vmware disks. You don't really need VM Workstation anymore.

Sunday, May 04, 2008

Trip to Kranji Reservoir

Actually, we were looking for Sungai Buloh Wetlands Reserve, but this reservoir place is also a cool place to hang out, especially when Singapore is experiencing a heat wave.
The 'water keys' or whatever they call it, it controls water flow when there is high tide from Selat Tebrau. On the other side is Kranji Reservoir.
This is the reservoir. There are a lot of people fishing here when we went.
Suaku-1 posing for photo...hehe...
Suaku-3 pointing where we are.
People fishing. Not sure if they caught anything the whole evening there though. I am not a fishing person, just don't have the patience to wait for the fish or prawn to bite.It is so huge! I saw an eagle or some predatory bird flying around catching fish. Unfortunately, my little camera is not powerful enough to capture the event. Looks like I need to upgrade to a digital SLR with telescoping lenses.
A family enjoying their Sunday quietly observing Johor Bahru.
Some other people watching some other thing....
Swamp land, quite wet and sticky (duh!). Nothing much to see. Some baby crabs, no mudskippers.
You can actually see Johor Bahru from here!A picture tells a thousand words.
That's me on a tree. Well, technically not 'on' the tree, I'm just standing on its roots.
Nice view of the sun through the swamp tree leaves.
Can you see the sun?
Colourful slippers, wet and smelly too!
Swamp sun.
Suaku-1 and Suaku-2 looking at fisherman throwing net.
Can you see the spider?
No? Try this picture.
Mrs Kitty Cat minding her own business when I took this photo.

Next time, we'll be visiting the Sungai Buloh Wetlands Reserve. We know where it is now!

Trip to Pulau Ubin

Me and 2 other friends went to Pulau Ubin one fine Saturday. I got the photos as proof!2 'suaku' going along with me to Pulau Ubin. Our first trip there, and we've been in Singapore for at least 7 years!
The boat that looks like our boat that brought us to Pulau Ubin.
The stretch of sandy beach near Changi Village near the docks.
The most suaku looking one of all!
Yeah, we went to see the Chek Jawa place. Unfortunately, the place is closing went we were about to arrive. Next time go in the morning, stupid!
The main mode of transportation on the island. Bicycles cost you 2 bucks for rental (whole day). Damn cheap man!
One tired suaku pushing her bike.

Check out Chek Jawa! It is in high tide so we don't see much of the life like crabs and mudskippers. But we do see jellyfishes (ouch!) and schools of fish.
Same picture different angle?
Yeah, she's looking for jellyfishes.
SQ1234 request landing permission in Changi Airport. I need nasi lemak!
Colonial sytle house built by British surveyor during the early 20th century. Should be before the Second World War.
Food was cheap too, had some sort of shell fish (no idea what its called in English), potato leaves and fried cuttle fish. Mmm....