Here is the function to read all WP DB definitions:
function get_wordpress_data() { $content = @file_get_contents( '../wp-config.php' ); if( ! $content ) { return false; } $params = [ 'db_name' => "/define.+?'DB_NAME'.+?'(.*?)'.+/", 'db_user' => "/define.+?'DB_USER'.+?'(.*?)'.+/", 'db_password' => "/define.+?'DB_PASSWORD'.+?'(.*?)'.+/", 'db_host' => "/define.+?'DB_HOST'.+?'(.*?)'.+/", 'table_prefix' => "/\\\$table_prefix.+?'(.+?)'.+/", ]; $return = []; foreach( $params as $key => $value ) { $found = preg_match_all( $value, $content, $result ); if( $found ) { $return[ $key ] = $result[ 1 ][ 0 ]; } else { $return[ $key ] = false; } } return $return; }
this returns an array like this:
array (size=5) 'db_name' => string '.........' 'db_user' => string '.........' 'db_password' => string '.........' 'db_host' => string 'localhost' 'table_prefix' => string 'wp_'
source share