['8.0', '8.4'], 'MariaDB' => ['10.11', '11.4']]; /** * Classifies a database server version string as returned by the server * (e.g. "8.4.11", "11.4.13-MariaDB", "5.5.5-10.11.6-MariaDB"). * * @return array{engine:string, version:string, status:'verified'|'unverified'|'unsupported'|'unknown'} * verified: same major.minor series as an exercised server (any patch version); unverified: at or above the minimum but a series that * was not exercised (for example a newer release); unsupported: below the minimum; unknown: the version string could not be read */ public static function database(string $serverVersion): array { $isMaria = stripos($serverVersion, 'mariadb') !== false; // MariaDB may report a "5.5.5-" compatibility prefix before its real version. $clean = (string) preg_replace('/^5\.5\.5-/', '', $serverVersion); if (!preg_match('/^(\d+)\.(\d+)(?:\.(\d+))?/', $clean, $m)) { return ['engine' => $isMaria ? 'MariaDB' : 'unknown', 'version' => $serverVersion, 'status' => 'unknown']; } $version = $m[1] . '.' . $m[2] . (isset($m[3]) ? '.' . $m[3] : ''); $engine = $isMaria ? 'MariaDB' : 'MySQL'; $min = $isMaria ? self::MIN_MARIADB : self::MIN_MYSQL; $status = match (true) { version_compare($m[1] . '.' . $m[2], $min, '<') => 'unsupported', in_array($m[1] . '.' . $m[2], self::VERIFIED_SERIES[$engine], true) => 'verified', default => 'unverified', }; return ['engine' => $engine, 'version' => $version, 'status' => $status]; } /** True only for a confirmed problem: a server older than the declared minimum. Unverified and unknown servers are not problems. */ public static function needsAttention(string $status): bool { return $status === 'unsupported'; } }