wp-cli / config-command

Generates and reads the wp-config.php file.
MIT License
38 stars 36 forks source link

Change mysql CLI call to native PHP function #158

Closed wojtekn closed 1 year ago

wojtekn commented 1 year ago

It fixes https://github.com/wp-cli/config-command/issues/152

In this diff, I propose to change the way of validating MySQL connection from the CLI command call to the native PHP function.

$wpdb is not accessible, so I used the native mysqli function, similar to what happens in $wpdb->db_connect().

Testing steps

  1. Prepare a directory that contains WordPress code
  2. Remove wp-config.php if it exists
  3. Try creating a config file using incorrect database credentials
../config-command/vendor/bin/wp config create --dbname=test --dbuser=test --dbpass=wrongpassword --locale=ro_RO --dbhost=127.0.0.1
  1. Confirm that the error is shown and mentions incorrect credentials, e.g.:
Error (1045) Access denied for user 'test'@'172.17.0.1' (using password: YES)% 
  1. Run the command with the correct database credentials
  2. Confirm that the config file was created and success message was displayed:
Success: Generated 'wp-config.php' file.
kozer commented 1 year ago

@wojtekn , can you please provide some test instructions here?