dqmgjp5930
2017-06-01 13:01
浏览 88
已采纳

SQL Like不工作字符串在php mysql中包含单引号

SQL LIKE is not working when string contains single quote ',
Below is my php code

  $keysearch = "St.Joseph's"; // Searching keyword containing single quotes
  $sql =mysqli_query("select id,name from tbl where name LIKE '%$keysearch%'");

It returns no result,
How can I search a string contain single quotes?
Is there any effective operator except 'LIKE' for comparing single quotes value in DB?

图片转代码服务由CSDN问答提供 功能建议

当字符串包含单引号'时,SQL LIKE不起作用,
Below 是我的 php代码

  $ keysearch =“St.Joseph's”;  //搜索包含单引号的关键字
 $ sql = mysqli_query(“select id,name from tbl where name LIKE'%$ keysearch%'”); 
   
 
 

它没有返回结果,
如何搜索包含单引号的字符串?
是否有任何有效的运算符除了'LIKE'用于比较DB中的单引号值?

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dp6319 2017-06-01 13:04
    已采纳

    Use addslashes() function of PHP as below,

    $sql =mysqli_query($con,"select id,name from tbl where name LIKE '%".addslashes($keysearch)."%'");
    
    打赏 评论

相关推荐 更多相似问题