phpmyadmin 中的错误虽然在 php 脚本中运行良好
好吧,这个很奇怪,我想我的 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
我在一种损失。我的问题的原因实际上有两个:
- 我的查询实际上是否存在我遗漏的问题?
- 如果不是,错误 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:
- Is there actually something wrong with my query that I am missing?
- 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
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?
您的表名或列名中是否有空格?如果是这样,请将它们括在反引号中:
Do you have spaces in any of your table or column names? If so, enclose them in backticks:
你应该做的是删除 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.