简体   繁体   English

MySQL Query太大了? 导致无响应的控制台

[英]MySQL Query too large? Results in unresponsive console

As I was trying to add a quote (via a PHP/HTML form) to my site that was particularly long, I noticed that the longer quotes did not get added via the MySQL query. 当我试图向我的网站添加一个特别长的引用(通过PHP / HTML表单)时,我注意到没有通过MySQL查询添加更长的引号。 The shorter ones got added just fine. 较短的那些添加得很好。

This is not a problem with the length of the columns in my table, the quotes are most definitely shorter than the limit (which is VARCHAR(600)). 这不是我表中列长度的问题,引号绝对短于限制(VARCHAR(600))。

When I try to manually enter the quotes into the database from the MySQL command line, hitting enter after entering the query properly does not result in a new prompt (it goes to the next line of the query instead). 当我尝试从MySQL命令行手动输入引号进入数据库时​​,在正确输入查询后按Enter键不会产生新的提示(而是转到查询的下一行)。 The query never executes. 查询永远不会执行。

The only way I can get to a new prompt is to force exit out of the MySQL command line and re-opening it. 我可以获得新提示的唯一方法是强制退出MySQL命令行并重新打开它。 Anyone know why this is happening? 任何人都知道为什么会这样吗?

EDIT : Here is my query. 编辑 :这是我的查询。 The first 3 values are irrelevant, I won't confuse anyone by explaining them. 前3个值是无关紧要的,我不会通过解释它们来混淆任何人。 The last 2 are the source and the quote. 最后2个是来源和报价。

EDIT2 : MySQL version is 5.5.8 EDIT2 :MySQL版本是5.5.8

THE QUERY THAT DOES NOT WORK 这是不行的

INSERT INTO quotes VALUES(NULL, 2, 20, 'http://www.mlb.com/news/article.jsp?ymd=20091104&content_id=7620238&vkey=news_nyy&fext=.jsp&c_id=nyy', 'He's the reason we're here. First of all, we wouldn't be in this stadium if it wasn't for him. We wouldn't have this group together if it wasn't for him. It's a special moment. We all wanted to win it for him.');

EXAMPLE OF A QUERY THAT WORKS 一个有效的查询示例

INSERT INTO quotes VALUES(NULL, 2, 20, 'http://www.mlb.com/news/article.jsp?ymd=20091104&content_id=7620238&vkey=news_nyy&fext=.jsp&c_id=nyy', 'I guess you could say that this is the best moment of my life right now," Matsui said. "If I were to look back, yes, this would be the best.');

To those downvoting, mind telling me why? 对于那些低调的人,请记住我的原因?

FINAL EDIT Got it... it's because of the single quotes in my quote. 最后编辑得到它...这是因为我引用的单引号。 Thank you. 谢谢。

The following things could cause the MySQL console to think that you have not yet finished your query, and there is more to enter: 以下情况可能导致MySQL控制台认为您尚未完成查询,还有更多要输入:

  • An unclosed quote, or backtick. 未公开的引用或反引号。
    • Usually due to the fact that you didn't escape a quote by doing \\' (for single quotes) or \\" (for double quotes). 通常是因为您没有通过执行\\' (对于单引号)或\\" (对于双引号)来逃避引用。
  • No semi-colon at the end of the query. 查询结尾没有分号。

Make sure you don't have either of those problems and the query should run. 确保您没有遇到这些问题,并且应该运行查询。

Edit following poster's edit: Yeah, looking at your query, you need to escape quotes by replacing ' with \\' whenever it is inside an item of data. 编辑以下海报的编辑:是的,查看您的查询,您需要通过在数据项内部替换' with \\'来转义引号。 PHP has a function to escape for you which is mysql_real_escape_string() . PHP有一个为你逃避的函数,即mysql_real_escape_string() You could also use prepared statements, which prevents this problem. 您还可以使用预准备语句来防止此问题。 See this question for more information. 有关更多信息,请参阅此问题

这是非常明显的,我的朋友......你在最后一个字符串中有单引号,而使用那些作为你的字符串边界...

When in the MySQL console, make sure you add a semicolon (;) to the end of the query. 在MySQL控制台中,请确保在查询末尾添加分号(;)。 Otherwise, it will expect more to the query. 否则,它会对查询有更多期望。

You've got single quotes inside your string, which is encapsulated in single quotes. 你的字符串中有单引号,用单引号封装。

You should be escaping your strings with mysql_real_escape_string (or something similar, like PDO): http://php.net/manual/en/function.mysql-real-escape-string.php 您应该使用mysql_real_escape_string (或类似的东西,如PDO)转义您的字符串: http//php.net/manual/en/function.mysql-real-escape-string.php

听起来你没有正确地转义引号中的'或'字符。查找任何'或'或\\字符并在它们之前添加\\。

You post no PHP code but your SQL suggests that you are omitting two basic steps: 您没有发布PHP代码,但您的SQL建议您省略两个基本步骤:

  1. Use prepared statements to inject data into your queries (or proper escaping functions) 使用预准备语句将数据注入查询(或正确的转义函数)
  2. Test the result of your DB calls and print/log error messages. 测试数据库调用的结果和打印/日志错误消息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM