phpmyadmin 中的错误虽然在 php 脚本中运行良好

发布于 2024-09-12 08:51:24 字数 1118 浏览 3 评论 0原文

好吧,这个很奇怪,我想我的 sql 查询一定有问题,但我没有发现它有什么问题。发生的情况是,我有一个在 php 脚本中运行的脚本,该脚本检索用户已注册的所有类别以及有多少其他人已注册同一类别。当我在 php 页面中运行查询时,速度非常慢,但确实返回结果。我想看看发生了什么,所以我去 phpmyadmin 运行相同的脚本,它非常快地返回结果计数,但随后给出了以下错误,其中通常会显示结果:

#1064 - You have an error in your SQL syntax; check the manual that corresponds
       to your MySQL server version for the right syntax to use near '' at line 1 

这是查询:

SELECT t1.category_id, t3.description AS 'Category',
    t1.list_type_id, t2.name, t1.status_id, t2.user_id,
    t2.email, UNIX_TIMESTAMP( t1.record_date ) AS 'RecordDate',
    (
        SELECT COUNT( category_id ) 
        FROM t1_sub
        WHERE t1_sub = t1.job_ctg_id AND
            t1_sub.list_type_id = t1.list_type_id AND
            t1_sub.status_id =44
    ) AS 'MatchingListings'
FROM t1
INNER JOIN t2 ON t2.id_rfp_vendor_data = t1.user_id
INNER JOIN t3 ON t3.type_lookup_id = t1.job_ctg_id
WHERE t1.status_id =43

我在一种损失。我的问题的原因实际上有两个:

  1. 我的查询实际上是否存在我遗漏的问题?
  2. 如果不是,错误 mysql 是否显示了我的脚本运行缓慢的原因,并且 php 有某种解决方法? (虽然这似乎不太可能,但我只需要询问即可确定)

谢谢!

Ok so this one is strange and I'm thinking there must be a problem in my sql query but I don't see anything wrong with it. What is happening is that I have a script that I am running in a php script that retrieves all categories that a user has signed up for as well as how many other people have signed up for the same category. When I run the query in the php page it is very slow but does return results. I wanted to see what was happening so I went to phpmyadmin to run the same script and it returns the count of the results very fast but then gives me the following error where the results would normally be displayed:

#1064 - You have an error in your SQL syntax; check the manual that corresponds
       to your MySQL server version for the right syntax to use near '' at line 1 

Here is the query:

SELECT t1.category_id, t3.description AS 'Category',
    t1.list_type_id, t2.name, t1.status_id, t2.user_id,
    t2.email, UNIX_TIMESTAMP( t1.record_date ) AS 'RecordDate',
    (
        SELECT COUNT( category_id ) 
        FROM t1_sub
        WHERE t1_sub = t1.job_ctg_id AND
            t1_sub.list_type_id = t1.list_type_id AND
            t1_sub.status_id =44
    ) AS 'MatchingListings'
FROM t1
INNER JOIN t2 ON t2.id_rfp_vendor_data = t1.user_id
INNER JOIN t3 ON t3.type_lookup_id = t1.job_ctg_id
WHERE t1.status_id =43

I am at a loss. The reason for my question is really two fold:

  1. Is there actually something wrong with my query that I am missing?
  2. If not, is the error mysql showing the reason why my script is running slow and that php has some way around this? (Though this seems like an unlikely possibility I just have to ask to be sure)

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

早茶月光 2024-09-19 08:51:24

PHPMyAdmin 可以自由稍微重写您的查询(例如,添加 LIMIT 0,30 子句以仅显示前 30 行)。

您可以启用查询日志并查看哪个查询实际在服务器上执行吗?

如果没有,请尝试从查询中删除元素,直到它起作用为止。向我们展示该查询。或者显示一些表定义?

PHPMyAdmin takes the liberty to slightly rewrite your queries (for example, adds the LIMIT 0,30 clause as to only show the first 30 lines).

Can you enable the query-log and see which query actually gets executed on the server?

If not, try removing elements from the query until it does work. Show us that query. Or show some table definitions?

单调的奢华 2024-09-19 08:51:24

您的表名或列名中是否有空格?如果是这样,请将它们括在反引号中:

`table name`

Do you have spaces in any of your table or column names? If so, enclose them in backticks:

`table name`
隔纱相望 2024-09-19 08:51:24

你应该做的是删除 phpmyadmin 并保证不再下载它。

然后启动命令行 mysql 提示符,并尝试相同的查询。这将告诉您该查询是否真的很糟糕,或者 phpmyadmin 是否只是为了其被误导的作者的变态乐趣而将其丢弃。

What you should do is delete phpmyadmin and promise never to download it again.

Then fire up a command-line mysql prompt, and try the same query. This will tell you whether the query is genuinely bad, or if phpmyadmin was simply trashing it for the perverted pleasure of its misguided authors.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文