@@ -62,30 +62,32 @@ protected function getConnection(): PDO
62
62
*/
63
63
private function unsetStatsExpiry ()
64
64
{
65
- if (version_compare ($ this ->getMySqlVersion (), '8.0.0 ' ) >= 0 ) {
65
+ $ isMySql = strpos ($ this ->getDatabaseVariable ('version_comment ' ), 'MySQL ' ) !== false ;
66
+ $ version = $ this ->getDatabaseVariable ('version ' );
67
+
68
+ if ($ isMySql && version_compare ($ version , '8.0.0 ' ) >= 0 ) {
66
69
$ this ->getConnection ()->exec ('SET information_schema_stats_expiry=0; ' );
67
70
}
68
71
}
69
72
70
73
/**
71
- * Get MySql version .
74
+ * Get database variable .
72
75
*
73
- * @throws UnexpectedValueException
76
+ * @param string $variable The variable
74
77
*
75
- * @return string The version
78
+ * @return string The value
76
79
*/
77
- private function getMySqlVersion ( ): string
80
+ protected function getDatabaseVariable ( string $ variable ): string
78
81
{
79
- $ statement = $ this ->getConnection ()->query ("SHOW VARIABLES LIKE 'version'; " );
80
-
81
- if ($ statement === false ) {
82
- throw new UnexpectedValueException ('Invalid sql statement ' );
82
+ $ statement = $ this ->getConnection ()->prepare ('SHOW VARIABLES LIKE ? ' );
83
+ if (!$ statement || $ statement ->execute ([$ variable ]) === false ) {
84
+ throw new UnexpectedValueException ('Invalid SQL statement ' );
83
85
}
84
86
85
87
$ row = $ statement ->fetch (PDO ::FETCH_ASSOC );
86
88
87
89
if ($ row === false ) {
88
- throw new UnexpectedValueException (' Version not found ' );
90
+ throw new UnexpectedValueException (sprintf ( ' Database variable not defined: %s ' , $ variable ) );
89
91
}
90
92
91
93
return (string )$ row ['Value ' ];
0 commit comments