gpt4 book ai didi

php - 操作 'UNION' 的排序规则 (utf8_general_ci,IMPLICIT) 和 (utf32_general_ci,IMPLICIT) 的非法混合

转载 作者:行者123 更新时间:2023-11-29 02:26:10 25 4
gpt4 key购买 nike

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

Illegal mix of collations (utf8_general_ci,IMPLICIT) and (utf32_general_ci,IMPLICIT) for operation '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>";
?>

最佳答案

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

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

关于php - 操作 'UNION' 的排序规则 (utf8_general_ci,IMPLICIT) 和 (utf32_general_ci,IMPLICIT) 的非法混合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21275815/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com