1.20.x charset_converter.inc public DatabaseCharsetConverter::convertTable($table_name, $charset = NULL, $collation = NULL)

Converts a table to a desired character set and collation.

Parameters

string $table_name: The table name to convert. This should be the actual table name in the database, with any table prefix already prepended.

string $charset: (Optional) The character set. Defaults to the constructor value.

string $collation: (Optional) The collation. Defaults to the constructor value.

Return value

bool: TRUE if the table is converted successfully, FALSE on failure.

Throws

PDOException

File

includes/database/charset_converter.inc, line 180

Class

DatabaseCharsetConverter
Character set converter for database tables.

Code

public function convertTable($table_name, $charset = NULL, $collation = NULL) {
  $this->connection->query("ALTER TABLE `$table_name` ROW_FORMAT=DYNAMIC ENGINE=INNODB");
  $sql = "ALTER TABLE `$table_name` CHARACTER SET = :charset COLLATE = :collation";
  $result = $this->connection->query($sql, array(
    ':charset' => $charset ? : $this->charset,
    ':collation' => $collation ? : $this->collation,
  ));
  if ($result) {
    $result = $this->convertTableFields($table_name, $charset, $collation);
    $this->connection->query("OPTIMIZE TABLE `$table_name`");
  }
  return $result;
}