Automattic\WooCommerce\Internal\Utilities
DatabaseUtil::create_primary_key()
Create a primary key for a table, only if the table doesn't have a primary key already.
Метод класса: DatabaseUtil{}
Хуков нет.
Возвращает
true|false
. True if the key has been created, false if the table already had a primary key.
Использование
$DatabaseUtil = new DatabaseUtil(); $DatabaseUtil->create_primary_key( $table_name, $columns );
- $table_name(строка) (обязательный)
- Table name.
- $columns(массив) (обязательный)
- An array with the index column names.
Код DatabaseUtil::create_primary_key() DatabaseUtil::create primary key WC 7.3.0
public function create_primary_key( string $table_name, array $columns ) { global $wpdb; if ( ! empty( $this->get_index_columns( $table_name ) ) ) { return false; } // phpcs:ignore WordPress.DB.PreparedSQL $wpdb->query( "ALTER TABLE $table_name ADD PRIMARY KEY(`" . join( '`,`', $columns ) . '`)' ); return true; }