gpt4 book ai didi

php - PDO 版本属性从何而来?

转载 作者:行者123 更新时间:2023-11-29 01:48:36 25 4
gpt4 key购买 nike

我为 PDO 数据库驱动程序返回了不同的版本字符串,我认为应该是相同的。通过在 PHP 中调用此方法获取版本:

Database::getConnection()->version()

内部是这样做的:

$this->getAttribute(PDO::ATTR_SERVER_VERSION)

所以它正在获取 PDO 驱动程序的 ATTR_SERVER_VERSION。我使用的驱动程序是 mysql,它是在 Linux 上。

在一台运行 PHP 5.6 的机器上,它返回 10.2.26-MariaDB-log

在另一台运行 PHP 7.2 的机器上,它返回 5.5.5-10.2.26-MariaDB

两者都有 MariaDB 10.2.26。我不知道 PHP 是否是它们不同的原因。版本字符串会像这样不同是有原因的吗?

最佳答案

这实际上来自于数据库。深入研究源代码,我看到 ATTR_SERVER_VERSION 实际上调用了 ZVAL_STRING(return_value, (char *)mysql_get_server_info(H->server));。关于 https://www.php.net/manual/en/function.mysql-get-server-info.php 的评论说是一样的

SELECT VERSION() as mysql_version

当我尝试时,我发现它们是匹配的。

 $pdo->getAttribute(PDO::ATTR_SERVER_VERSION);
// '5.7.24-0ubuntu0.18.04.1'

mysql> select version();
+-------------------------+
| version() |
+-------------------------+
| 5.7.24-0ubuntu0.18.04.1 |
+-------------------------+

MySQL 版本命令说:

Returns a string that indicates the MySQL server version. The string uses the utf8 character set. The value might have a suffix in addition to the version number. See the description of the version system variable in Section 5.1.7, “Server System Variables”.

-- version

The version number for the server. The value might also include a suffix indicating server build or configuration information. -log indicates that one or more of the general log, slow query log, or binary log are enabled. -debug indicates that the server was built with debugging support enabled

MariaDB,从 MySQL fork ,has the same version variable

Description: Server version number. It may also include a suffix withconfiguration or build information. -debug indicates debugging supportwas enabled on the server, and -log indicates at least one of thebinary log, general log or slow query log are enabled, for example10.0.1-MariaDB-mariadb1precise-log. From MariaDB 10.2.1, this variable can be set at startup in order to fake the server version.

Commandline: -V, --version[=name] (>= MariaDB 10.2.1), --version (<=MariaDB 10.2.0)

Scope: Global

Dynamic: No

Type: string

至于服务器之间的不匹配,这是 MariaDB 为解决复制服务器问题而添加的东西,但大多数客户端会将其删除。 src from GitHub issue

MySQL replication slave code decides what the master can do (binlogformat, etc) by looking at the first character of the version as sentin the handshake packet. When MariaDB went 10.0, MySQL slaves startedto think it's version 1, and refused to replicate from it.

As a workaround we've implemented this version prefix. MariaDB sendsan impossible combination in the handshake packet — the version"5.5.5" and "support authentication plugins" in the capability field.The MariaDB client library detects that and transparently removes thefake version prefix.

Of course if you link with not mariadb-aware client library, theprefix will be not removed, and you'll see it in the application.

关于php - PDO 版本属性从何而来?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57496570/

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