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条)

报告相同问题?

悬赏问题

  • ¥20 求数据集和代码#有偿答复
  • ¥15 关于下拉菜单选项关联的问题
  • ¥20 java-OJ-健康体检
  • ¥15 rs485的上拉下拉,不会对a-b<-200mv有影响吗,就是接受时,对判断逻辑0有影响吗
  • ¥15 使用phpstudy在云服务器上搭建个人网站
  • ¥15 应该如何判断含间隙的曲柄摇杆机构,轴与轴承是否发生了碰撞?
  • ¥15 vue3+express部署到nginx
  • ¥20 搭建pt1000三线制高精度测温电路
  • ¥15 使用Jdk8自带的算法,和Jdk11自带的加密结果会一样吗,不一样的话有什么解决方案,Jdk不能升级的情况
  • ¥15 画两个图 python或R