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;
qa_base_db_connect(null);
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'];
unset($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']);
exit;
}
}
// 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',
'title',
'icon',
'parent_id',
'position',
'pcount'),
'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;
}
mysql_free_result($result);
*/
$result = json_encode($top_categories);
echo $result;
}
Somebody can help me?
Thank a lot.