Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
0 votes
in Plugins by
edited by


I am writting a plugin which use ajax to update data in database (In the plugin I added a new table).

However, I faced this error: 'Illegal mix of collations for operation 'UNION'' when query data. 

Here is my ajax code:


define('WEBROOT_DIR', dirname(dirname(dirname(__FILE__))).'/');
require_once WEBROOT_DIR."qa-include/qa-base.php";
require_once QA_INCLUDE_DIR."qa-app-format.php";
require_once QA_INCLUDE_DIR."qa-db.php";
require_once QA_INCLUDE_DIR."qa-db-selects.php";
// Connect to database
global $qa_db;
mysql_query("SET character_set_client=utf8", $qa_db);
mysql_query("SET character_set_connection=utf8", $qa_db);
// Get params from the request
$params = array();
foreach($_GET as $key=>$val){
$params[$key] = $val;
$cmd = $params['cmd'];
// Register biz function
$function_array = array(
'get_top' => array('func' => 'get_top_only', 'args' => $params),
// Find function and execute
foreach($function_array as $key => $func){
if ($key == $cmd){
call_user_func($func['func'], $func['args']);
// If function not found or error, return NG
echo 'NG'; 
// Get just top category
function get_top_only(){
$args = func_get_args();
// Select top category
$top_category_selectspec = array(
'columns' => array('category_id',
'source' => 'qaec_category WHERE parent_id=0 ORDER BY position',
'arraykey' => 'category_id',
$top_categories = qa_db_select_with_pending($top_category_selectspec);
$sql = 'SELECT * FROM qaec_category WHERE parent_id=0 ORDER BY position';
$result = mysql_query($sql);
while ($row = mysql_fetch_assoc($result)) {
$top_categories[] = $row;
$result = json_encode($top_categories);
echo $result;
Somebody can help me?
Thank a lot.



Q2A version: 1.4.3

1 Answer

0 votes


I had the same issue on mysql 5.0.18, question2answer 1.5

issue itself is described at: http://dev.mysql.com/doc/refman/5.1/en/charset-repertoire.html

To hot fix "question2answer" script itself I have removed all:


in qa-include/qa-db-install.php and reinstalled - so it uses default collation for every column - so far works fine :)

Best Regards

Welcome to the Q&A site for Question2Answer.

If you have a question about Q2A, please ask here, in English.

To report a bug, please create a new issue on Github or ask a question here with the bug tag.

If you just want to try Q2A, please use the demo site.