关于MySQL和PHP的时区调整
记得实习的时候弄那个WIKI网站的时候,显示服务器这段显示的时间老师为格林威治时间(比北京时间慢了8小时),当时多方查找原因,
记得实习的时候弄那个WIKI网站的时候,显示服务器这段显示的时间老师为格林威治时间(比北京时间慢了8小时),当时多方查找原因,网上收集资料也未解决。后来在学校自己弄了一下,又到网上找到一些资料,终于解决了问题,原来是在PHP设置的问题。
现将解决方法写于此处,注意修改:C:\windows\php.ini文件就可以了,原来是我们一直在PHP安装目录那边去找此文件,当然就错了哦。另:以下大部分内容源于互联网的,,哈哈
PHP 脚本端的时区设置可以在 php.ini 下设置 date.timezone 键的值为 'Asia/Shanghai' 即可。但是通常共享虚拟主机本身没有修改 php.ini 权限。这个时候就应该在程序公共部分加入
ini_set('date.timezone','Asia/Shanghai');
动态修改 php.ini 的设置。之后可以测试一下时间是否正确:
var_dump(date());
如果服务器的本地时间是正确的,那么一般就能解决问题了。附,PHP 5.1 以上提供了专门的函数修改对应的时区:
date_default_timezone_set('Asia/Shanghai');
建议使用此函数,因为更通用一些。对应 'Asia/Shanghai' 其他可以使用的大陆时区还有:Asia/Chongqing、Asia/Shanghai 、Asia/Urumqi(依次为重庆,上海,乌鲁木齐);港台地区可用:Asia/Macao、Asia/Hong_Kong、Asia/Taipei(依次为澳门,香港,台北);还有新加坡:Asia/Singapore;其他可用的值是:Etc/GMT-8、Singapore、Hongkong、PRC;老外好像把北京漏调了。
MySQL的时区问题:
方法一
1,在mysql的命令模式下使用
mysql > select CURTIME();
或
mysql > select now();
看当前时间是否正确,可以看到mysql当前使用的是那一个时区的时间。
2,在mysql命令行中更改时区
mysql > SET time_zone = '+8:00'; # 此为北京时,我们所在东8区
mysql> flush privileges; # 立即生效
此时mysql时区已更改正确,与系统时区都使用为 Shanghai时间了。
#### 这种方法好像只能在终端上使用,退出终端后时间又会变成原来的,看来只能重启mysql了。
3,重启mysql也应没有问题,此时mysql会主动读取系统时间。
方法二:
如果mysql数据库可以重启,直接重启,mysql应可以立即主动读取系统时间,如果不行则更改mysql的配置文件(mysql.cnf)
在my.cnf的 [mysqld]区域中加上
default-time_zone = '+8:00' #此为北京时。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Apple's latest releases of iOS18, iPadOS18 and macOS Sequoia systems have added an important feature to the Photos application, designed to help users easily recover photos and videos lost or damaged due to various reasons. The new feature introduces an album called "Recovered" in the Tools section of the Photos app that will automatically appear when a user has pictures or videos on their device that are not part of their photo library. The emergence of the "Recovered" album provides a solution for photos and videos lost due to database corruption, the camera application not saving to the photo library correctly, or a third-party application managing the photo library. Users only need a few simple steps

How to use MySQLi to establish a database connection in PHP: Include MySQLi extension (require_once) Create connection function (functionconnect_to_db) Call connection function ($conn=connect_to_db()) Execute query ($result=$conn->query()) Close connection ( $conn->close())

To handle database connection errors in PHP, you can use the following steps: Use mysqli_connect_errno() to obtain the error code. Use mysqli_connect_error() to get the error message. By capturing and logging these error messages, database connection issues can be easily identified and resolved, ensuring the smooth running of your application.

Using the database callback function in Golang can achieve: executing custom code after the specified database operation is completed. Add custom behavior through separate functions without writing additional code. Callback functions are available for insert, update, delete, and query operations. You must use the sql.Exec, sql.QueryRow, or sql.Query function to use the callback function.

This article will provide a detailed introduction to how to install and register a Bitcoin trading application. The Bitcoin trading app allows users to manage and trade cryptocurrencies such as Bitcoin. The article guides users through the installation and registration process step by step, including downloading applications, creating accounts, performing identity verification, and first deposit. The goal of the article is to provide beginners with clear and easy-to-understand guidelines to help them easily enter the world of Bitcoin trading.

JSON data can be saved into a MySQL database by using the gjson library or the json.Unmarshal function. The gjson library provides convenience methods to parse JSON fields, and the json.Unmarshal function requires a target type pointer to unmarshal JSON data. Both methods require preparing SQL statements and performing insert operations to persist the data into the database.

How to integrate GoWebSocket with a database: Set up a database connection: Use the database/sql package to connect to the database. Store WebSocket messages to the database: Use the INSERT statement to insert the message into the database. Retrieve WebSocket messages from the database: Use the SELECT statement to retrieve messages from the database.

To avoid PHP database connection errors, follow best practices: check for connection errors and match variable names with credentials. Use secure storage or environment variables to avoid hardcoding credentials. Close the connection after use to prevent SQL injection and use prepared statements or bound parameters.
