Archive | April, 2008

Escape String

function escape_string($varr){
//Escape array or string in postgre
if(is_array($varr)){
foreach($varr as $key => $value){
$result[$key] = trim(pg_escape_string($value));
}
}else{
$result = trim(pg_escape_string($varr));
}
return $result;
}

Read more

PHP Number Leading Zero’s

<?php
$id = 3;
echo sprintf(“%04d”,$id);
//result 0003
?>

Read more

PostgreSQL Calculate Age From Birthdate

SELECT EXTRACT(year from AGE(NOW(), ‘1985-08-21′)) as “age”;

Read more