doqrjrc95405 2012-07-06 21:25
浏览 132
已采纳

mysql查询中双引号和单引号之间有什么区别

I found the issue and now my insert query works, but I don't understand why. Here is my current working query:

$add_movie = mysql_query("INSERT INTO ownedmovies VALUES ('', '{$movie_data['Title']}',
    '{$movie_data['Year']}', '{$movie_data['Rated']}', '{$movie_data['Runtime']}',
    '{$movie_data['Genre']}', '{$movie_data['Director']}', '{$movie_data['Writer']}',
    '{$movie_data['Actors']}', \"{$movie_data['Plot']}\", '{$movie_data['imdbRating']}')");

Notice that I used double quotes around the plot field and normal around everything else. When I did the plot field the same way as the others, it would not error but nothing would get inserted into the table... now it works perfectly.

Could anyone enlighten me on why this is?

Thank you

  • 写回答

4条回答 默认 最新

  • doushai7225 2012-07-06 21:29
    关注

    I suspect that your plot string contains a single quote. To avoid the problem you should be escaping your string values using mysql_real_escape_string, or (better) use parameterized queries.

    Your "solution" of changing the single quote to a double quote may appear to work in this case, but it will fail if the plot string contains a double quote.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 adb push异常 adb: error: 1409-byte write failed: Invalid argument
  • ¥15 android报错 brut.common.BrutException: could not exec (exit code = 1)
  • ¥15 nginx反向代理获取ip,java获取真实ip
  • ¥15 eda:门禁系统设计
  • ¥50 如何使用js去调用vscode-js-debugger的方法去调试网页
  • ¥15 376.1电表主站通信协议下发指令全被否认问题
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥15 复杂网络,变滞后传递熵,FDA
  • ¥20 csv格式数据集预处理及模型选择
  • ¥15 部分网页页面无法显示!