protected function convertToCharacterSetAndCollation(string $characterSet, string $collation, string $outputPathAndFilename = null, bool $verbose = false)
    {
        $statements = ['SET foreign_key_checks = 0'];

        $statements[] = 'ALTER DATABASE ' . $this->connection->quoteIdentifier($this->persistenceSettings['backendOptions']['dbname']) . ' CHARACTER SET ' . $characterSet . ' COLLATE ' . $collation;

        $tableNames = $this->connection->getSchemaManager()->listTableNames();
        foreach ($tableNames as $tableName) {
            $statements[] = 'ALTER TABLE ' . $this->connection->quoteIdentifier($tableName) . ' DEFAULT CHARACTER SET ' . $characterSet . ' COLLATE ' . $collation;
            $statements[] = 'ALTER TABLE ' . $this->connection->quoteIdentifier($tableName) . ' CONVERT TO CHARACTER SET ' . $characterSet . ' COLLATE ' . $collation;
        }

        $statements[] = 'SET foreign_key_checks = 1';

        if ($outputPathAndFilename === null) {
            try {
                $this->connection->beginTransaction();
                foreach ($statements as $statement) {
                    if ($verbose) {
                        $this->outputLine($statement);
                    }
                    $this->connection->exec($statement);
                }
                $this->connection->commit();
            } catch (\Exception $exception) {
                $this->connection->rollBack();
                $this->outputLine($exception->getMessage());
                $this->outputLine('[ERROR] The transaction was rolled back.');
            }
        } else {
            file_put_contents($outputPathAndFilename, implode(';' . PHP_EOL, $statements) . ';');
        }
    }
protected function convertToCharacterSetAndCollation(string $characterSet, string $collation, string $outputPathAndFilename = null, bool $verbose = false)
    {
        $statements = ['SET foreign_key_checks = 0'];

        $statements[] = 'ALTER DATABASE ' . $this->connection->quoteIdentifier($this->persistenceSettings['backendOptions']['dbname']) . ' CHARACTER SET ' . $characterSet . ' COLLATE ' . $collation;

        $tableNames = $this->connection->getSchemaManager()->listTableNames();
        foreach ($tableNames as $tableName) {
            $statements[] = 'ALTER TABLE ' . $this->connection->quoteIdentifier($tableName) . ' DEFAULT CHARACTER SET ' . $characterSet . ' COLLATE ' . $collation;
            $statements[] = 'ALTER TABLE ' . $this->connection->quoteIdentifier($tableName) . ' CONVERT TO CHARACTER SET ' . $characterSet . ' COLLATE ' . $collation;
        }

        $statements[] = 'SET foreign_key_checks = 1';

        if ($outputPathAndFilename === null) {
            try {
                $this->connection->beginTransaction();
                foreach ($statements as $statement) {
                    if ($verbose) {
                        $this->outputLine($statement);
                    }
                    $this->connection->exec($statement);
                }
                $this->connection->commit();
            } catch (\Exception $exception) {
                $this->connection->rollBack();
                $this->outputLine($exception->getMessage());
                $this->outputLine('[ERROR] The transaction was rolled back.');
            }
        } else {
            file_put_contents($outputPathAndFilename, implode(';' . PHP_EOL, $statements) . ';');
        }
    }
protected function convertToCharacterSetAndCollation ( string $ characterSet , string $ collation , string $ outputPathAndFilename = null , bool $ verbose = false ) { $ statements = [ 'SET foreign_key_checks = 0' ] ; $ statements [ ] = 'ALTER DATABASE ' . $ this -> connection -> quoteIdentifier ( $ this -> persistenceSettings [ 'backendOptions' ] [ 'dbname' ] ) . ' CHARACTER SET ' . $ characterSet . ' COLLATE ' . $ collation ; $ tableNames = $ this -> connection -> getSchemaManager ( ) -> listTableNames ( ) ; foreach ( $ tableNames as $ tableName ) { $ statements [ ] = 'ALTER TABLE ' . $ this -> connection -> quoteIdentifier ( $ tableName ) . ' DEFAULT CHARACTER SET ' . $ characterSet . ' COLLATE ' . $ collation ; $ statements [ ] = 'ALTER TABLE ' . $ this -> connection -> quoteIdentifier ( $ tableName ) . ' CONVERT TO CHARACTER SET ' . $ characterSet . ' COLLATE ' . $ collation ; } $ statements [ ] = 'SET foreign_key_checks = 1' ; if ( $ outputPathAndFilename === null ) { try { $ this -> connection -> beginTransaction ( ) ; foreach ( $ statements as $ statement ) { if ( $ verbose ) { $ this -> outputLine ( $ statement ) ; } $ this -> connection -> exec ( $ statement ) ; } $ this -> connection -> commit ( ) ; } catch ( \ Exception $ exception ) { $ this -> connection -> rollBack ( ) ; $ this -> outputLine ( $ exception -> getMessage ( ) ) ; $ this -> outputLine ( '[ERROR] The transaction was rolled back.' ) ; } } else { file_put_contents ( $ outputPathAndFilename , implode ( ';' . PHP_EOL , $ statements ) . ';' ) ; } }
Convert the tables in the current database to use given character set and collation.

@param string $characterSet Character set to convert to
@param string $collation Collation to set, must be compatible with the character set
@param string $outputPathAndFilename
@param boolean $verbose
@throws ConnectionException
@throws DBALException
Convert the tables in the current database to use given character set and collation .