@@ -198,58 +198,8 @@ public function connect()
198198 throw new UnsupportedAdapterException ('The MySQLi extension is not available ' );
199199 }
200200
201- /*
202- * Unlike mysql_connect(), mysqli_connect() takes the port and socket as separate arguments. Therefore, we
203- * have to extract them from the host string.
204- */
205- $ port = isset ($ this ->options ['port ' ]) ? $ this ->options ['port ' ] : 3306 ;
206-
207- if (preg_match ('/^unix:(?P<socket>[^:]+)$/ ' , $ this ->options ['host ' ], $ matches )) {
208- // UNIX socket URI, e.g. 'unix:/path/to/unix/socket.sock'
209- $ this ->options ['host ' ] = null ;
210- $ this ->options ['socket ' ] = $ matches ['socket ' ];
211- $ this ->options ['port ' ] = null ;
212- } elseif (
213- preg_match (
214- '/^(?P<host>((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))(:(?P<port>.+))?$/ ' ,
215- $ this ->options ['host ' ],
216- $ matches
217- )
218- ) {
219- // It's an IPv4 address with or without port
220- $ this ->options ['host ' ] = $ matches ['host ' ];
221-
222- if (!empty ($ matches ['port ' ])) {
223- $ port = $ matches ['port ' ];
224- }
225- } elseif (preg_match ('/^(?P<host>\[.*\])(:(?P<port>.+))?$/ ' , $ this ->options ['host ' ], $ matches )) {
226- // We assume square-bracketed IPv6 address with or without port, e.g. [fe80:102::2%eth1]:3306
227- $ this ->options ['host ' ] = $ matches ['host ' ];
228-
229- if (!empty ($ matches ['port ' ])) {
230- $ port = $ matches ['port ' ];
231- }
232- } elseif (preg_match ('/^(?P<host>(\w+:\/{2,3})?[a-z0-9\.\-]+)(:(?P<port>[^:]+))?$/i ' , $ this ->options ['host ' ], $ matches )) {
233- // Named host (e.g example.com or localhost) with or without port
234- $ this ->options ['host ' ] = $ matches ['host ' ];
235-
236- if (!empty ($ matches ['port ' ])) {
237- $ port = $ matches ['port ' ];
238- }
239- } elseif (preg_match ('/^:(?P<port>[^:]+)$/ ' , $ this ->options ['host ' ], $ matches )) {
240- // Empty host, just port, e.g. ':3306'
241- $ this ->options ['host ' ] = 'localhost ' ;
242- $ port = $ matches ['port ' ];
243- }
244-
245- // ... else we assume normal (naked) IPv6 address, so host and port stay as they are or default
246-
247- // Get the port number or socket name
248- if (is_numeric ($ port )) {
249- $ this ->options ['port ' ] = (int ) $ port ;
250- } else {
251- $ this ->options ['socket ' ] = $ port ;
252- }
201+ // Extract host and port or socket from host option
202+ $ this ->setHostPortSocket (3306 );
253203
254204 $ this ->connection = mysqli_init ();
255205
0 commit comments