diff --git a/core/database_api.php b/core/database_api.php index 5bbeb6cbc4..619a2c28be 100644 --- a/core/database_api.php +++ b/core/database_api.php @@ -959,16 +959,20 @@ function db_get_table( $p_name ) { $t_table = $p_name; } - $t_prefix = config_get_global( 'db_table_prefix' ); - $t_suffix = config_get_global( 'db_table_suffix' ); - - if( $t_prefix ) { - $t_table = $t_prefix . '_' . $t_table; + # Determine table prefix including trailing '_' + $t_prefix = trim( config_get_global( 'db_table_prefix' ) ); + if( !empty( $t_prefix ) && '_' != substr( $t_prefix, -1 ) ) { + $t_prefix .= '_'; + } + # Determine table suffix including leading '_' + $t_suffix = trim( config_get_global( 'db_table_suffix' ) ); + if( !empty( $t_suffix ) && '_' != substr( $t_suffix, 0, 1 ) ) { + $t_suffix = '_' . $t_suffix; } - $t_table .= $t_suffix; + # Physical table name + $t_table = $t_prefix . $t_table . $t_suffix; db_check_identifier_size( $t_table ); - return $t_table; } diff --git a/core/plugin_api.php b/core/plugin_api.php index 93ce1de11e..530092108b 100644 --- a/core/plugin_api.php +++ b/core/plugin_api.php @@ -233,16 +233,13 @@ function plugin_table( $p_name, $p_basename = null ) { $t_current = $p_basename; } - $t_table_name = config_get_global( 'db_table_prefix' ); - if( !empty( $t_table_name ) ) { - $t_table_name .= '_'; + # Determine plugin table prefix including trailing '_' + $t_prefix = trim( config_get_global( 'db_table_plugin_prefix' ) ); + if( !empty( $t_prefix ) && '_' != substr( $t_prefix, -1 ) ) { + $t_prefix .= '_'; } - $t_table_name .= - config_get_global( 'db_table_plugin_prefix' ) . - $t_current . '_' . $p_name . - config_get_global( 'db_table_suffix' ); - return $t_table_name; + return db_get_table( $t_prefix . $t_current . '_' . $p_name ); } /**