|
1 | 1 | <?php |
2 | 2 |
|
| 3 | +require_once dirname(__DIR__, 4) . '/tests/probe_cache.inc'; |
| 4 | + |
3 | 5 | function get_default_host(): string { |
4 | 6 | static $host = null; |
5 | 7 | if ($host === null) { |
@@ -110,24 +112,41 @@ function default_mysqli_connect(): \mysqli{ |
110 | 112 | function mysqli_check_skip_test(): void { |
111 | 113 | mysqli_connect_or_skip(); |
112 | 114 | } |
113 | | -function mysqli_connect_or_skip() { |
114 | | - try { |
115 | | - return default_mysqli_connect(); |
116 | | - } catch (\mysqli_sql_exception) { |
117 | | - die(sprintf("skip Can't connect to MySQL Server - [%d] %s", mysqli_connect_errno(), mysqli_connect_error())); |
| 115 | + |
| 116 | +function mysqli_connect_or_skip(): mysqli { |
| 117 | + $connection = null; |
| 118 | + $configuration = [ |
| 119 | + get_default_host(), |
| 120 | + get_default_port(), |
| 121 | + get_default_user(), |
| 122 | + get_default_password(), |
| 123 | + get_default_database(), |
| 124 | + get_default_socket(), |
| 125 | + get_environment_connection_flags(), |
| 126 | + ]; |
| 127 | + |
| 128 | + $reason = ProbeCache::getFailure('mysqli', $configuration, static function () use (&$connection): ?string { |
| 129 | + try { |
| 130 | + $connection = default_mysqli_connect(); |
| 131 | + return null; |
| 132 | + } catch (mysqli_sql_exception $e) { |
| 133 | + return sprintf("Can't connect to MySQL Server - [%d] %s", mysqli_connect_errno(), mysqli_connect_error()); |
| 134 | + } |
| 135 | + }); |
| 136 | + |
| 137 | + if (is_string($reason)) { |
| 138 | + die("skip $reason"); |
118 | 139 | } |
| 140 | + |
| 141 | + return $connection; |
119 | 142 | } |
120 | 143 | function have_innodb(mysqli $link): bool { |
121 | 144 | $res = $link->query("SELECT SUPPORT FROM INFORMATION_SCHEMA.ENGINES WHERE ENGINE = 'InnoDB'"); |
122 | 145 | $supported = $res->fetch_column(); |
123 | 146 | return $supported === 'YES' || $supported === 'DEFAULT'; |
124 | 147 | } |
125 | 148 | function mysqli_check_innodb_support_skip_test(): void { |
126 | | - try { |
127 | | - $link = default_mysqli_connect(); |
128 | | - } catch (\mysqli_sql_exception) { |
129 | | - die(sprintf("skip Can't connect to MySQL Server - [%d] %s", mysqli_connect_errno(), mysqli_connect_error())); |
130 | | - } |
| 149 | + $link = mysqli_connect_or_skip(); |
131 | 150 | if (! have_innodb($link)) { |
132 | 151 | die(sprintf("skip Needs InnoDB support")); |
133 | 152 | } |
|
0 commit comments