WordPress at a glance
function is not described

wpdb::set_prefix() public WP 2.5.0

Sets the table prefix for the WordPress tables.

{} It's a method of the class: wpdb{}

No Hooks.

Return

String/WP_Error. Old prefix or WP_Error on error.

Usage

global $wpdb;
$wpdb->set_prefix( $prefix, $set_table_names );
$prefix(string) (required)
Alphanumeric name for the new prefix.
$set_table_names(true/false)
Whether the table names, e.g. wpdb::$posts, should be updated or not.
Default: true

Changelog

Since 2.5.0 Introduced.

Code of wpdb::set_prefix() WP 5.5.1

<?php
public function set_prefix( $prefix, $set_table_names = true ) {

	if ( preg_match( '|[^a-z0-9_]|i', $prefix ) ) {
		return new WP_Error( 'invalid_db_prefix', 'Invalid database prefix' );
	}

	$old_prefix = is_multisite() ? '' : $prefix;

	if ( isset( $this->base_prefix ) ) {
		$old_prefix = $this->base_prefix;
	}

	$this->base_prefix = $prefix;

	if ( $set_table_names ) {
		foreach ( $this->tables( 'global' ) as $table => $prefixed_table ) {
			$this->$table = $prefixed_table;
		}

		if ( is_multisite() && empty( $this->blogid ) ) {
			return $old_prefix;
		}

		$this->prefix = $this->get_blog_prefix();

		foreach ( $this->tables( 'blog' ) as $table => $prefixed_table ) {
			$this->$table = $prefixed_table;
		}

		foreach ( $this->tables( 'old' ) as $table => $prefixed_table ) {
			$this->$table = $prefixed_table;
		}
	}
	return $old_prefix;
}