A
A
Alexander N++2016-04-08 19:29:04
linux
Alexander N++, 2016-04-08 19:29:04

Mysql php insert into database and getting date back is not correct how to solve?

There are 2 servers 1 under php / http another under the database
Both databases have the same time zone sec per sec.
In the PHP MSK
configs In the Mysql configs
on the server where php insert the date into the table with
set time_zone = '+00:00'
the script itself to understand what and how...

$date = date('Y-m-d H:i:s');
        echo "PHP DATE ". $date;
        echo "<br>";
        $sql = 'INSERT INTO test_date SET `date`=:date';
        $id = Yii::$app->db->createCommand($sql,[':date' => $date ])->execute();
        $date = Yii::$app->db->createCommand("select date from test_date where id=:id",[':id' => $id ])->queryScalar();
        echo "MYSQL DATE ". $date;

Prints
PHP DATE 2016-04-08 19:19:32
MYSQL DATE 2016-04-08 19:11:02
Cut off set time_zone = '+00:00'
Prints
PHP DATE 2016-04-08 19:13:47
MYSQL DATE 2016-04-08 22:11:02
Why such a hard time difference?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
LightAir, 2016-04-14
@LightAir

Setting up a timezone in mysql and php itif.ru/ustanovka-vremennoj-zony-v-php-i-mysql

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question