【问题标题】:Illegal mix of collations (utf8_general_ci,IMPLICIT) and (utf32_general_ci,IMPLICIT) for operation 'UNION'用于操作“UNION”的排序规则 (utf8_general_ci,IMPLICIT) 和 (utf32_general_ci,IMPLICIT) 的非法混合
【发布时间】:2014-01-22 06:32:35
【问题描述】:

当我选择一个选项时,我有在dbase 中通过多选列表搜索的代码我有这个错误:

排序规则的非法混合 (utf8_general_ci,IMPLICIT) 和 (utf32_general_ci,IMPLICIT) 用于操作“UNION”

问题出在哪里?

这是我的代码:

<?php
$expertsearch = trim($_GET['nm']);

include("connect.php");

mysql_query("SET NAMES utf8");

$expertdata = mysql_fetch_object(mysql_query("SELECT * FROM experts WHERE ID = $expertsearch"));
$expertname = $expertdata->expert_name;

$sql = "SELECT * FROM eridb WHERE 
eridb.expert1 = $expertsearch OR eridb.expert2 = $expertsearch OR eridb.expert3 =  $expertsearch UNION

SELECT * FROM kacaredb WHERE 
kacaredb.expert1 = $expertsearch OR kacaredb.expert2 = $expertsearch OR kacaredb.expert3     = $expertsearch UNION

SELECT * FROM mwedb WHERE 
mwedb.expert1 = $expertsearch OR mwedb.expert2 = $expertsearch OR mwedb.expert3 =     $expertsearch UNION

SELECT * FROM secdb WHERE 
secdb.expert1 = $expertsearch OR secdb.expert2 = $expertsearch OR secdb.expert3 =     $expertsearch UNION

SELECT * FROM seecdb WHERE 
seecdb.expert1 = $expertsearch OR seecdb.expert2 = $expertsearch OR seecdb.expert3 =  $expertsearch ";

$res = mysql_query($sql);

echo "<table border='1'>

$count = 0;
while($row=mysql_fetch_object($res))
{
$count = $count+1;
echo "<tr>";
echo "<td>" . $count . "</td>";
echo "<td>" . $row->id . "</td>";
echo "<td>" . $row->nameofresearch . "</td>";
echo "<td>" . $row->dateofstart . "</td>";
echo "<td>" . $row->dateofend . "</td>";
echo "<td>" . $row->budget . "</td>";
echo "<td>" . $row->requestedby . "</td>";
echo "<td>" . $row->projectstatus . "</td>";
echo "<td>" . $expertname . "</td>";
echo "<td>" . $row->projectstatus . "</td>";
echo "</tr>";
}

if($res){
echo "Successful";
echo "<BR>";
}
else {
echo "ERROR";
echo "<br>";
echo mysql_error();
echo "<a href='main1.php'><br>Please try again </a>";
}
echo "</table>";
?>

【问题讨论】:

    标签: php mysql


    【解决方案1】:

    在您的情况下,无法同时选择具有不同字符集/排序规则的列,utf8 和 utf32。在您的表中找到这些列(运行 SHOW CREATE TABLE 语句)并尝试使用 CONVERT 函数来转换它们,例如-

    SELECT CONVERT(column_name USING utf8) FROM experts
      UNION
    SELECT CONVERT(column_name USING utf8) FROM eridb
    

    【讨论】:

      【解决方案2】:

      它的基本问题,也有一个简单的解决方案。

      只需将要匹配的两列字符类型设置为相同即可。

      (utf8_general_ci,IMPLICIT) 和 (utf32_general_ci,IMPLICIT) 表明您正在尝试将 utf8_general_ci 与 utf32_general_ci 匹配..

      所以只需改变列的字符类型。

      【讨论】:

      • 我正在制作我所有的数据库 utf8_general_ci
      • 我正在制作我所有的数据库 utf8_general_ci 并且仍然是问题
      猜你喜欢
      • 2012-07-30
      • 2010-11-03
      • 2010-09-16
      • 2020-04-15
      • 2023-03-21
      • 2017-10-17
      • 1970-01-01
      • 2016-02-19
      • 2010-10-30
      相关资源
      最近更新 更多