gpt4 book ai didi

php - 我应该在哪里放置 SET time_zone = 'America/New_York'

转载 作者:行者123 更新时间:2023-11-29 20:51:19 26 4
gpt4 key购买 nike

如何通过此类查询 MySQL 并在每次查询后设置 time_zone?我对于在以下代码块中放置时区命令的位置遇到一些麻烦:

class MyDB {

private $connection;
public $last_query;
private $magic_quotes_active;
private $real_escape_string_exists;
function __construct(){
$this->open_connection();
$this->magic_quotes_active = get_magic_quotes_gpc();
$this->real_escape_string_exists = function_exists("mysql_real_escape_string");
}

public function open_connection(){
$this->connection = mysql_connect(DB_SERVER, DB_USER, DB_PASS);
if(!$this->connection){
die("Database connection failed: " . mysql_connect());
} else {
$db_select = mysql_select_db(DB_NAME, $this->connection);
if(!$db_select){
die("Database selection failed: " . mysql_error());

}
}
}

public function close_connection(){
if(isset($this->connection)){
mysql_close($this->connection);
unset($this->connection);
}
}

public function query($sql) {
$this->last_query = $sql;
$result = mysql_query($sql, $this->connection);
$this->confirm_query($result);
return $result;
}

public function escape_value($value){
if($this->real_escape_string_exists){ // PHP v.4.3.0 or higher
//undo any magic quote effects so mysl_real_escape_string can do the work
if($this->magic_quotes_active){
$value = stripslashes($value);
}
$value = mysql_real_escape_string($value);
} else { // before PHP v.4.3.0
// if magic quotes aren't already on then add slashes manually
if(!$this->magic_quotes_active) {
$value = addslashes($value);
}
// if magic quotes are active, then the slashes already exist
}
return $value;
}

public function fetch_array($result_set){
return mysql_fetch_array($result_set);
}

public function num_rows($result_set){
return mysql_num_rows($result_set);
}

public function insert_id($result_set){
return mysql_insert_id($this->connection);
}

public function affected_rows($result_set){
return mysql_affected_rows($this->connection);
}

private function confirm_query($result){
if(!$result){
$output = "Database query failed: " . mysql_error() . "<br /><br />";
$output .= "Last SQL query: ". $this->last_query;
die($output);
}

}
}

$database = new MyDB();$db =& $database;

最佳答案

你可以像这样动态设置它: date_default_timezone_set('美国/纽约');

关于php - 我应该在哪里放置 SET time_zone = 'America/New_York',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38024530/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com