如何将 MYSQL TIMEZONE 更改为 GMT 格式,如 PHP 中的此函数:/ SET GMT TIMEZONE /date_default_timezone_set('Etc/GMT');
我的数据库类在这里:
class DB {
private static $instance;
private $MySQLi;
private function __construct(array $dbOptions){
$this->MySQLi = @ new mysqli( $dbOptions['db_host'],
$dbOptions['db_user'],
$dbOptions['db_pass'],
$dbOptions['db_name'] );
if (mysqli_connect_errno()) {
throw new Exception('Database error.');
}
$this->MySQLi->set_charset("utf8");
}
public static function init(array $dbOptions){
if(self::$instance instanceof self){
return false;
}
self::$instance = new self($dbOptions);
}
public static function getMySQLiObject(){
return self::$instance->MySQLi;
}
public static function query($q){
return self::$instance->MySQLi->query($q);
}
public static function prepare($q){
return self::$instance->MySQLi->prepare($q);
}
public static function esc($str){
return self::$instance->MySQLi->real_escape_string(htmlspecialchars($str));
}
}
我在其他文件中的查询是这样的:
DB::query('UPDATE `calendar_data` SET `data` = "'.DB::esc(json_encode($array)).'", `upcoming_time` = "'.date('Y-m-d H:i:s', $upcoming).'", `time_now` = NOW() WHERE `id` = "1"');
我应该在哪里将查询插入到类中以运行一次?
谢谢!
$this->MySQLi->set_charset("utf8");
$this->MySQLi->query("SET timezone = 'GMT'");
- 不工作。如果我使用 NOW(),则插入服务器时间 (GMT-4)。哪里有问题???