@@ -94,8 +94,15 @@ function qa_db_connect($failhandler = null)
9494 // From Q2A 1.5, we explicitly set the character encoding of the MySQL connection, instead of using lots of "SELECT BINARY col"-style queries.
9595 // Testing showed that overhead is minimal, so this seems worth trading off against the benefit of more straightforward queries, especially
9696 // for plugin developers.
97- if (!$ db ->set_charset ('utf8 ' ))
97+ if ($ db ->set_charset (QA_MYSQL_CHARSET )) {
98+ $ sql = 'SET NAMES ' . QA_MYSQL_CHARSET ;
99+ if (QA_MYSQL_COLLATION !== null ) {
100+ $ sql .= ' COLLATE ' . QA_MYSQL_COLLATION ;
101+ }
102+ $ db ->query ($ sql );
103+ } else {
98104 qa_db_fail_error ('set_charset ' , $ db ->errno , $ db ->error );
105+ }
99106
100107 qa_report_process_stage ('db_connected ' );
101108
@@ -174,6 +181,23 @@ function qa_db_disconnect()
174181 }
175182}
176183
184+ /**
185+ * Return the default charset and collation string to use in CREATE TABLE statements. For fields that
186+ * have not been set an implicit charset or collation, these values will be assigned at creation time.
187+ * Collation might be null to provide backwards compatibility with Q2A 1.8.6 and before.
188+ * @param string $charset
189+ * @param string $collation
190+ * @return string
191+ */
192+ function qa_get_table_charset_collation ($ charset = QA_MYSQL_CHARSET , $ collation = QA_MYSQL_COLLATION )
193+ {
194+ $ sql = 'DEFAULT CHARACTER SET ' . $ charset ;
195+ if ($ collation !== null ) {
196+ $ sql .= ' COLLATE ' . $ collation ;
197+ }
198+
199+ return $ sql ;
200+ }
177201
178202/**
179203 * Run the raw $query, call the global failure handler if necessary, otherwise return the result resource.
0 commit comments