Skip to content

Commit 108fbdd

Browse files
authored
Merge pull request #10 from BeAPI/fix/undefined-database-name
fallback to querying the dataname name is `dbname` property is null
2 parents cffaa7c + 380ea2d commit 108fbdd

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"homepage": "https://github.com/beapi/wp-cli-light-db-export",
66
"license": "MIT",
77
"require": {
8-
"php": ">=5.6"
8+
"php": ">=7.0"
99
},
1010
"authors": [
1111
{

src/wp-cli-light-db-export.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,10 @@ class WP_CLI_DB_Light_Export extends WP_CLI_DB_Light_Export_Base {
185185
public function export( $positional_args, $assoc_args = [] ) {
186186
global $wpdb;
187187

188-
$database_name = $wpdb->dbname;
188+
$database_name = $wpdb->dbname ?? $wpdb->get_var('SELECT DATABASE();'); // fallback to querying the database if `dbname` is not defined
189+
if ( empty( $database_name ) ) {
190+
\WP_CLI::error( "Couldn't get database's name" );
191+
}
189192

190193
/**
191194
* Filename to export (required)

0 commit comments

Comments
 (0)