PDO set time zone

Hai folks

i am very new to PDO. I have created a db connection using PDO and setting the timezone as follows.


/*** mysql hostname ***/
$hostname = 'localhost';

/*** mysql username ***/
$username = 'xxxxxx';

/*** mysql password ***/
$password = 'xxxxx';

try {
    $db = new PDO("mysql:host=$hostname;dbname=xxxxx", $username, $password);
    /*** echo a message saying we have connected ***/
    //echo 'Connected to database';
    array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET time_zone = \'+03:00\'')    ;
}catch(PDOException $e){
    echo $e->getMessage();

Now i calls this file in to scripts where we need database operations as follows

but i am getting this error.

Warning:  date(): It is not safe to rely on the system's timezone
settings. You are *required* to use the date.timezone setting or the 
date_default_timezone_set() function. In case you used any of those 
methods and you are still getting this warning, you most likely 
misspelled the timezone identifier. We selected the timezone 'UTC' for 
now, but please set date.timezone to select your timezone. in /home4...

Tells you what to do in the warning message…it’s not your database that’s having a problem, it’s PHP itself.

1 Like

I just put this on top of my script


1 Like

Thank you both of you guys.
yes now its clear its a php error and yes added the function (see below) as you stated and it works!!!


//set time zone
$timezone = "Asia/Riyadh"; 
  echo 'Warning! Time zone not correctly set.';


This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.