我安装了新的Ubuntu,我的代码遇到了MySQL问题.
( ! ) Warning: PDOStatement::execute(): SQLSTATE[HY000]: General error: 3065
Expression #2 of ORDER BY clause is not in SELECT list, references column 'clicshopping_test_ui.p.products_date_added' which is not in SELECT list; this is incompatible with DISTINCT
in /home/www//boutique/includes/OM/DbStatement.php on line 97s
Run Code Online (Sandbox Code Playgroud)
似乎MySQL 5.7不允许这样的请求:
select .... distinct with order by rand(), p.products_date_added DESC
Run Code Online (Sandbox Code Playgroud)
如果我使用它,它的工作原理:
select distinct .... with order by rand(),
Run Code Online (Sandbox Code Playgroud)
如何解决这种情况?
我在PHP中的SQL请求
$Qproduct = $OSCOM_PDO->prepare('select distinct p.products_id,
p.products_price
from :table_products p left join :table_specials s on p.products_id = s.products_id
where products_status = :products_status
and products_view = :products_view
and p.products_archive = :products_archive
order by rand(),
p.products_date_added DESC
limit :products_limit');
$Qproduct->bindInt(':products_status', 1);
$Qproduct->bindInt(':products_view', 1);
$Qproduct->bindInt(':products_archive', 0);
$Qproduct->bindInt(':products_limit',
(int)MODULE_FRONT_PAGE_NEW_PRODUCTS_MAX_DISPLAY);
Run Code Online (Sandbox Code Playgroud)
Jus*_*iak 38
如果您拥有对服务器的控制权并且您正在运行遗留代码而无法轻松更改,则可以通过运行查询来调整服务器的SQL模式并在启动期间删除"only_full_group_by"
SET GLOBAL sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''));
或者添加sql_mode=''
到my.cnf文件中.
如果你有可能,最好更改你的代码,但如果没有,这将禁用该警告.
Wol*_*ack 13
要解决此问题,请打开以下文件:
/etc/mysql/mysql.conf.d/mysqld.cnf
Run Code Online (Sandbox Code Playgroud)
并在 [mysqld] 块下添加以下行
sql-mode=""
Run Code Online (Sandbox Code Playgroud)
Pau*_*NGE 13
SET GLOBAL sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''));
SET SESSION sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''));
Run Code Online (Sandbox Code Playgroud)
但如果您重新启动服务器,则可能必须重新运行它。
[mysqld]
# RESOLVE order-by-clause-is-not-in-select-list by removing ONLY_FULL_GROUP_BY from the sql-mode list
sql-mode="STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION"
Run Code Online (Sandbox Code Playgroud)
小智 6
如果您有 phpMyAdmin:
1-转到变量选项卡
2-搜索标签“sql模式”
3-编辑内容并删除模式:“ONLY_FULL_GROUP_BY”
4-保存
注意:不要忘记验证逗号分隔符
小智 1
尝试这个:
SELECT p.products_id, p.products_price
FROM :table_products p
LEFT JOIN :table_specials s on p.products_id = s.products_id
WHERE
products_status = :products_status AND
products_view = :products_view AND
p.products_archive = :products_archive
ORDER BY rand(), p.products_date_added DESC
GROUP BY p.products_id,p.products_price
LIMIT :products_limit
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
20870 次 |
最近记录: |