Hendra Setiawan Hendra Setiawan - 11 days ago 5
SQL Question

How to create Holiday Function in PHP?

I'm trying to make a function to generate holiday in PHP.
I've stored the holiday date in Oracle Table:

HOLIDAY

01-JAN-15

03-JAN-15

04-JAN-15

etc

My question is, how to make a function to get holiday date?
I mean, I need to find out that is_holiday('01-JAN-15') holiday is TRUE.

Here's my source code:



<?php
include "config/connect.php";
function is_holiday($thedate)
{
$sql = OCIParse($connect, "SELECT * FROM UF2T_HOLIDAY WHERE HOLIDAY = '".$thedate."'");
ociexecute($sql);
$result = oci_fetch_array($sql);

if(!empty($result[0]))
{
$holiday = "TRUE";
}
else
{
$holiday = "FALSE";
}
return $holiday;
}
echo is_holiday("08-JAN-15");
?>





This code doesn't work and always return FALSE.
What I'm supposed to do to make this code work?

Additional information:
I try to run it outside of a function, something like this :

<?php
include "config/connect.php";

$thedate = '01-JAN-15';
$sql = OCIParse($connect, "SELECT HOLIDAY FROM UF2T_HOLIDAY WHERE HOLIDAY = '".$thedate."'");
ociexecute($sql);
$result = oci_fetch_array($sql);

if(!empty($result[0]))
{
$holiday = "TRUE";
}
else
{
$holiday = "FALSE";
}

echo $holiday;
?>


This code is work. So I think the problem is around the function. Any suggestion? Please help. Thanks in advance.
Sorry for my bad English. :D

teo teo
Answer

I think, that problem is, that variable $connect is not available in your function. Try this:

function is_holiday($thedate, $connect)

and then call the function:

echo is_holiday("08-JAN-15", $connect);