gpt4 book ai didi

php - PHP 和 MySQL 中相同查询的不同 SQL 结果

转载 作者:行者123 更新时间:2023-11-29 13:46:40 25 4
gpt4 key购买 nike

经过快速搜索,我没有找到问题的解决方案,因此我发布了一个新问题。

所以我必须从 Web 界面(使用 PHP)在 MySQL 数据库中创建 View 。

我使用PEAR框架与MySQL(5.0.26)连接

我有 SQL 请求:

CREATE VIEW test AS SELECT cswc.code_de_la_copie, cswc.service_de_reference, cswc.libelle_de_la_copie, cswc.direction_de_securite_logique
FROM pressi_copiesServiceWithCibles cswc LEFT OUTER JOIN pressi_servicesReferenceWithCibles srwc ON cswc.service_de_reference = srwc.code_du_service
WHERE cswc.cible is null
AND (srwc.cible LIKE '%£DOMAIN£%' OR srwc.cible LIKE '%$DOMAIN$%');

当我直接在本地 MySQL 数据库上执行此请求时,我得到了 470 行的结果。

但是,当我在 PHP 代码中执行此请求时,我得到了不同的结果(我有 386 行),我不知道为什么!

$values['request'] = "SELECT cswc.code_de_la_copie, cswc.service_de_reference, cswc.libelle_de_la_copie, cswc.direction_de_securite_logique
FROM pressi_copiesServiceWithCibles cswc LEFT OUTER JOIN pressi_servicesReferenceWithCibles srwc ON cswc.service_de_reference = srwc.code_du_service
WHERE cswc.cible is null
AND (srwc.cible LIKE '%£DOMAIN£%' OR srwc.cible LIKE '%$DOMAIN$%');";

$baseView = "test";

$sqlView = 'CREATE VIEW '.$baseView.' AS '.$values['request'];
$res =& $this->mdb2->query($sqlView);
if (PEAR::isError($res)) {
return false;
}

此外,在这之前我已经创建了 6 个 View ,没有任何问题(PHP 和 MySQL 中的结果相同)

感谢您的帮助

最佳答案

请注意,您与数据库的连接还具有用于查询中包含的任何字符串值的 CHARSETCOLLATION。尽管您的查询在这两种情况下看起来是相同的,但从 MySQL 服务器的角度来看,它一定不同。

通过 PHP 连接时和通过 MySQL 控制台连接时,客户端 CHARSET(和/或 COLLATION)可能有所不同。

请参阅MySQL manual for more information on the client charset and collation .

为了进行比较,您可以使用以下查询:

SHOW VARIABLES LIKE 'character_set%';
SHOW VARIABLES LIKE 'collation%';

关于php - PHP 和 MySQL 中相同查询的不同 SQL 结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17315741/

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