WP_CLI\Utils
mysql_host_to_cli_args()
No Hooks.
Returns
Array
Usage
mysql_host_to_cli_args( $raw_host );
- $raw_host(string) (required)
- MySQL host string, as defined in wp-config.php.
mysql_host_to_cli_args() mysql host to cli args code WP-CLI 2.13.0-alpha
function mysql_host_to_cli_args( $raw_host ) {
$assoc_args = [];
/**
* If the host string begins with 'p:' for a persistent db connection,
* replace 'p:' with nothing.
*/
if ( substr( $raw_host, 0, 2 ) === 'p:' ) {
$raw_host = substr_replace( $raw_host, '', 0, 2 );
}
$host_parts = explode( ':', $raw_host );
if ( count( $host_parts ) === 2 ) {
list( $assoc_args['host'], $extra ) = $host_parts;
$extra = trim( $extra );
if ( is_numeric( $extra ) ) {
$assoc_args['port'] = (int) $extra;
$assoc_args['protocol'] = 'tcp';
} elseif ( '' !== $extra ) {
$assoc_args['socket'] = $extra;
}
} else {
$assoc_args['host'] = $raw_host;
}
return $assoc_args;
}