gpt4 book ai didi

php - 查询在 phpmyadmin 中运行,但不通过应用程序运行

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

嗨,我有一个有趣的问题。

更新:从下面的评论来看,这似乎是尝试同时运行多个查询的问题。我以为既然我是在 phpmyadmin 中做的,那么一切都很好。如何运行多个查询?我正在使用mysqli?我正在使用 mysql 5.x 并使用 mysqli

我正在从我的应用程序运行查询,如果查询不起作用,我会将其回显到屏幕上。伴随着 is 的错误

当我运行我的应用程序时,我将查询打印到屏幕上并出现此错误。

您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,了解在 'ALTER TABLE tmp_bulletins ADD INDEX (bb_id); 附近使用的正确语法。 ' 在第 13 行

当我复制回显到屏幕上的查询并在 phpmyadmin 中运行它时,它每次都工作正常。然后,我尝试获取屏幕上回显的查询,并通过我的应用程序在数据库上运行该查询,但它不起作用。

据我所知,完全相同的查询(即打印到我的屏幕上)正在通过 phpmyadmin 工作,但不是通过我的应用程序工作。

有什么原因可能会发生这种情况吗? phpmyadmin 在数据库上运行查询之前是否会对查询进行一些更改?

这是查询

CREATE TEMPORARY TABLE tmp_bulletins

SELECT {$table}.id AS bb_id,count(bb_replies.id) AS num_responses,bb_locations.title AS location,bb_locations.description AS location_description,bb_categories.title AS category,bb_categories.description AS category_description,Concat(users.first_name,' ',users.last_name) AS full_name,users.first_name AS first_name,users.last_name as last_name,users.id AS user_id,{$table}.title AS post_title,{$table}.content,{$table}.created_date,{$table}.rank
FROM `{$table}`
LEFT JOIN bb_locations ON {$table}.bb_locations_id = bb_locations.id
LEFT JOIN bb_categories ON {$table}.bb_categories_id = bb_categories.id
LEFT JOIN users ON {$table}.users_id = users.id
LEFT JOIN bb_replies ON {$table}.id = bb_replies.bbs_id
WHERE `bb_locations_id` IN ({$locations_csv}) AND `bb_categories_id` IN ({$categories_csv}) {$addWhere}
GROUP BY bb_id,location,location_description,category,category_description,first_name,last_name,user_id,post_title,content,created_date,rank
{$order} {$limit} ;

ALTER TABLE tmp_bulletins ADD INDEX (`bb_id`);


CREATE TEMPORARY TABLE tmp_ratings

SELECT bbs_id,
sum(CASE WHEN user_id = {$user_id} THEN like_dislike_id END) AS thisUsersRating,
SUM(CASE WHEN like_dislike_id = 2 THEN 1 ELSE 0 END) AS likes,
SUM(CASE WHEN like_dislike_id = 1 THEN 1 ELSE 0 END) AS dislikes
FROM bb_ratings
GROUP BY bbs_id;

ALTER TABLE tmp_ratings ADD INDEX (`bbs_id`);

SELECT * FROM tmp_bulletins
LEFT JOIN tmp_ratings on tmp_bulletins.bb_id = tmp_ratings.bbs_id;

以及它生成的查询(编辑我们说话时的外观)

    CREATE TEMPORARY TABLE tmp_bulletins 
SELECT bbs.id AS bb_id,count(bb_replies.id) AS num_responses,
bb_locations.title AS
location,bb_locations.description AS location_description,
bb_categories.title AS
category,bb_categories.description AS category_description,
Concat(users.first_name,' ',users.last_name) AS full_name,
users.first_name AS first_name,
users.last_name as last_name,users.id AS user_id,
bbs.title AS post_title,
bbs.content,bbs.created_date,bbs.rank FROM `bbs`
LEFT JOIN bb_locations ON bbs.bb_locations_id = bb_locations.id
LEFT JOIN bb_categories ON bbs.bb_categories_id = bb_categories.id
LEFT JOIN users ON bbs.users_id = users.id LEFT JOIN bb_replies ON bbs.id = bb_replies.bbs_id WHERE `bb_locations_id` IN (1,2) AND `bb_categories_id` IN (1,2)
GROUP BY bb_id,location,location_description,category,category_description,first_name,last_name,user_id,post_title,content,created_date,rank LIMIT 0,5; ALTER TABLE tmp_bulletins
ADD INDEX (`bb_id`);

CREATE TEMPORARY TABLE tmp_ratings
SELECT bbs_id, sum(CASE WHEN user_id = 1 THEN like_dislike_id END) AS thisUsersRating, SUM(CASE WHEN like_dislike_id = 2 THEN 1 ELSE 0 END) AS likes,
SUM(CASE WHEN like_dislike_id = 1 THEN 1 ELSE 0 END) AS dislikes FROM bb_ratings GROUP BY bbs_id;
ALTER TABLE tmp_ratings ADD INDEX (`bbs_id`);

SELECT * FROM tmp_bulletins LEFT JOIN tmp_ratings on tmp_bulletins.bb_id = tmp_ratings.bbs_id

最佳答案

去掉分号。

关于php - 查询在 phpmyadmin 中运行,但不通过应用程序运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4293895/

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