Caught exception

Hello,

The below code works on my home machine… but not on my Linux machine, I am unable to figure out the problem, please help


require_once("dbconnection.php");

function coun_list()
{
$rs=mysql_query("select name from timezones") or die(mysql_error());
while($row=mysql_fetch_row($rs))
  {
   $tzone=$row[0];
   if($tzone=='Asia/Calcutta') $tzone='Asia/Kolkata';
   try {
       $tz = new DateTimeZone("$tzone");
       $lt=$tz->getLocation();
       $lat=$lt['latitude'];
       $lon=$lt['longitude'];
       echo "$tzone";		
       }
      catch (Exception $e) {
        echo 'Caught exception: ',  $e->getMessage(), "\
";
       }
  }
}

coun_list();

I get the below error on my Linux machine,

Caught exception: DateTimeZone::__construct() [datetimezone.--construct]: Unknown or bad timezone ()

The same code works fine without any problem on other machine. Please help me to figure out the issue…

Nice question, yes I have the DB, I have also tried to print those values, $tz and $lt are not printing any values, The firstline itself displaying the error and then its not proceeding…

Printr $tz and $lt to see what/if it’s returning valid values… or add/remove lines one at a time to see which one is bombing. I’d remove the try/catch for this so you can line at a time check it.

Uhm… also, try using $row[‘name’] instead of $row[0] – you can never trust numbered indexes.

I have a silly question - does the linux server in question even have timezonedb installed and up to date?
http://www.php.net/manual/en/datetime.installation.php

function coun_list()
{
$rs=mysql_query("select name from timezones") or die(mysql_error());
while($row=mysql_fetch_row($rs))
  {
   $tzone=$row[0];
   echo $tzone=$row[0]; 

   try {
   [COLOR="Red"] /*   $tz=new DateTimeZone( $tzone );
       $lt=$tz->getLocation();
       $lat=$lt['latitude'];
       $lon=$lt['longitude']; */[/COLOR]
       if($lat!=0 && $lon!=0)
       echo $tzone;
       }
      catch (Exception $e) {
        echo 'Caught exception: ',  $e->getMessage(), "\
";
       }
  }
}

coun_list();

If I comment these lines, then I am able to get the data from the DB, If I uncomment these lines the code is not working.

shouldnt actually matter in this case ($tzone is a string anyway), because PHP will unfurl the variable into it’s string form. If tzone was an array or object, you’d have problems.

That said, it’s better practice to do it without the quotes.

As far as the original problem goes… have you checked your database to make sure it’s actually got data in the name column?

$tz = new DateTimeZone("$tzone");

SB,

$tz = new DateTimeZone( $tzone );

no?

I have modified the code, but still I am getting the same error:(

function coun_list()
{
$rs=mysql_query("select name from timezones") or die(mysql_error());
while($row=mysql_fetch_row($rs))
  {
   $tzone=$row[0];
   try {
       $tz = new DateTimeZone("$tzone");
       $lt=$tz->getLocation();
       $lat=$lt['latitude'];
       $lon=$lt['longitude'];
       echo "$tzone";		
       }
      catch (Exception $e) {
        echo 'Caught exception: ',  $e->getMessage(), "\
";
       }
  }
}

coun_list();

What is the value of $tzone when you get the error?

Just put echo before $tzone=$row[0];, i.e.

echo $tzone=$row[0];

What value of $tzone is being used?

Valid timezones appear to include ‘Asia/Calcutta’ but not, ‘Asia/Kolkata’.

Hi,

The Timezone version what the machine has is

"Olson" Timezone Database Version 	2010.9