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!

2009/12/01

php soap wget curl

php.ini has the following pertinent settings:

default_socket_timeout = 120
max_execution_time = 60
memory_limit = 20M

In soap client, connection_timeout is equivalent to default_socket_timeout.

<?php

$soapClient = new SoapClient('http://www.example.com/path/to.wsdl',
array('connection_timeout' => 120));

?>

Looks like soapclient use similar technique as file_get_contents() does
to get wsdl file. But unlike wget, file_get_contents generates distinct
packet for each line of HTTP request. Server doesn't reply on these
small chunks.

To let PHP behave like wget:

Define the following function:

function curl_file_get_contents($URL)
{
$c = curl_init();
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($c, CURLOPT_URL, $URL);
$contents = curl_exec($c);
curl_close($c);

if ($contents) return $contents;
else return FALSE;
}

And replace all file_get_contents entries with curl_file_get_contents.

2009/11/05

two select

Two selects:

SELECT cart_name as tag, count(cart_name) as frequency
From
  (SELECT distinct cart_name , account_id
   FROM `account_cart`
   where cart_name REGEXP '^[a-z]+'
) as tb1
Group by cart_name



2009/11/03

empty matches 0 in sql????

page_id = '', the following sql still work.

SELECT SQL_CACHE a.unique_id, b.banner_id, a.page_id, a.grp, a.page_pos,
a.order_seq, b.banner_type, b.image_name, b.link, b.target, b.params, ''
AS sku_list
FROM page_banners_link a, page_banners b
WHERE a.page_id = ''
AND site_id = '0'
AND a.banner_id = b.banner_id
ORDER BY a.page_pos, a.page_id, a.order_seq
LIMIT 0 , 30

2009/11/02

how to purge master logs

> on master:    mysql -p

> 

> mysql >  show master status;

> 

> 

> on slave:   mysql -p

> 

> mysql > show slave status;

> 

> 

> If both master and slave are processing the same replication log file

> (meaning that replication is running correctly),  then you can safely

> run the following commend on master:

> 

> 

> mysql > purge master logs to "current-replication-log-filename";

 

2009/10/26

window.location

function onSelectChangeSite(){
   var dropdown = document.getElementById("snssite");
   var index = dropdown.selectedIndex;
   var ddVal = dropdown.options[index].value;

   var current = window.location;
   var re1 = /\?custm/;
   var re2 = /\?/;

   if (re1.test(current))
      window.location = "?custm=" + ddVal;
   else if (re2.test(current))
      window.location = current + "&custm=" + ddVal;
   else
      window.location = "?custm=" + ddVal;

}

2009/10/25

perl note part2

1.      @line= <STDIN>

Chomp(@line)

print @line;

CTR+D in linux CTR+Z in window to end of standard input

2.      A lot of default

Sub list_from_a_to_b{

            If ($a>$b){

            $a;

            }

            Else{

            $b;

            }

}

$a, $b are global variables. No return needed

Or use

Sub list_from_a_to_b{

            ($a,$b) = @_

Or use

$a = $_[0];

$b = $_[1];