使用"set time_zone = ..."连接到数据库后,更改时区. [英] Changing time zone after connecting to database using "set time_zone = ..."

查看:63
本文介绍了使用"set time_zone = ..."连接到数据库后,更改时区.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

连接数据库后,我正尝试将时区更改为欧洲/伦敦".这是我的原始代码:

I'm trying to change the time zone to "Europe/London" right after connecting to my database. This was my original code:

$pdo = new PDO('mysql:host=localhost;dbname=exampletable', 'exampleuser', 'examplepassw', array(\PDO::MYSQL_ATTR_INIT_COMMAND =>  'SET NAMES utf8');

然后我将其更改为以下代码,但是显然这不是更改时区的正确方法,因为我遇到了错误.

And I changed it into the following code but apparently that's not the right way to change the time zone cause I get an error.

$pdo = new PDO('mysql:host=localhost;dbname=exampletable', 'exampleuser', 'examplepassw', array(\PDO::MYSQL_ATTR_INIT_COMMAND =>  'SET NAMES utf8', 'SET time_zone = 'Europe/London''));

如何更改从PDO开始的时区?

How can I change the time zone starting from PDO?

推荐答案

在其他人的帮助下(请参见评论),我设法找到了完成这项工作的代码:

With some help of others (see comments), I managed to find the code that does the job:

$pdo = new PDO('mysql:host=localhost;dbname=exampletable', 
               'exampleuser', 
               'examplepassw', 
               [PDO::MYSQL_ATTR_INIT_COMMAND =>"SET NAMES utf8;SET time_zone = 'Europe/London'"]);

这篇关于使用"set time_zone = ..."连接到数据库后,更改时区.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆