@@ -166,6 +166,9 @@ private static function get_initial_locale() {
166166 * [--insecure]
167167 * : Retry API download without certificate validation if TLS handshake fails. Note: This makes the request vulnerable to a MITM attack.
168168 *
169+ * [--ssl]
170+ * : Enable SSL connection.
171+ *
169172 * ## EXAMPLES
170173 *
171174 * # Standard wp-config.php file
@@ -201,6 +204,7 @@ public function create( $_, $assoc_args ) {
201204 'dbcollate ' => '' ,
202205 'locale ' => self ::get_initial_locale (),
203206 'config-file ' => rtrim ( ABSPATH , '/ \\' ) . '/wp-config.php ' ,
207+ 'ssl ' => false ,
204208 ];
205209 $ assoc_args = array_merge ( $ defaults , $ assoc_args );
206210 if ( empty ( $ assoc_args ['dbprefix ' ] ) ) {
@@ -226,12 +230,18 @@ public function create( $_, $assoc_args ) {
226230 $ host = substr ( $ host , 0 , $ socket_pos );
227231 }
228232
233+ $ flags = 0 ;
234+
235+ if ( $ assoc_args ['ssl ' ] ) {
236+ $ flags = MYSQLI_CLIENT_SSL ;
237+ }
238+
229239 if ( file_exists ( $ socket ) ) {
230240 // If dbhost is a path to a socket
231- mysqli_real_connect ( $ mysql , null , $ assoc_args ['dbuser ' ], $ assoc_args ['dbpass ' ], null , null , $ socket );
241+ mysqli_real_connect ( $ mysql , null , $ assoc_args ['dbuser ' ], $ assoc_args ['dbpass ' ], null , null , $ socket, $ flags );
232242 } else {
233243 // If dbhost is a hostname or IP address
234- mysqli_real_connect ( $ mysql , $ host , $ assoc_args ['dbuser ' ], $ assoc_args ['dbpass ' ] );
244+ mysqli_real_connect ( $ mysql , $ host , $ assoc_args ['dbuser ' ], $ assoc_args ['dbpass ' ], null , null , null , $ flags );
235245 }
236246 } catch ( mysqli_sql_exception $ exception ) {
237247 WP_CLI ::error ( 'Database connection error ( ' . $ exception ->getCode () . ') ' . $ exception ->getMessage () );
0 commit comments