SQLl Like无法正常工作的字符串在php mysql中包含单引号 [英] SQLl Like is not working string contain single quotes in php mysql

查看:141
本文介绍了SQLl Like无法正常工作的字符串在php mysql中包含单引号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当字符串包含单引号'
时,SQL LIKE无法正常工作 以下是我的 php代码

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%'");

不返回结果,
如何搜索包含单引号的字符串?
除了'LIKE'之外,还有没有其他有效的运算符可用于比较数据库中的单引号?

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?

推荐答案

使用PHP的addslashes()函数,如下所示,

Use addslashes() function of PHP as below,

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

这篇关于SQLl Like无法正常工作的字符串在php mysql中包含单引号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆