Php 插入前插入单引号

Php 插入前插入单引号,php,mysql,sql,string,Php,Mysql,Sql,String,我的php代码返回一些值,我正在尝试在数据库中插入 $string = '1,here,Skincare composition against free radicals'; //this is returned '(insert into import (S.No,Name,Title)) values ($string)' 需要将该字符串转换为正确的格式以插入到db中 '1','here','Skincare composition against free radicals'

我的php代码返回一些值,我正在尝试在数据库中插入

$string =  '1,here,Skincare composition against free radicals'; //this is returned

'(insert into import (S.No,Name,Title)) values ($string)'  
需要将该字符串转换为正确的格式以插入到db中

'1','here','Skincare composition against free radicals'  //This is expected
内爆应该怎么做?但我不知道怎么做?

试试看

$string =  "1,here,Skincare composition against free radicals";
$varList = explode(",", $string);
$newQuery = "INSERT INTO `import` (`S.No`,`Name`,`Title`) VALUES ('" . $varList[0] . "','" . $varList[1] . "','" . $varList[2] . "')";
但是查询在
SQL注入中易受攻击,请阅读下面的文章,了解如何防范它

其他来源


这应该行得通,因为您的SQL是一个字符串…@christopher,但您需要
s,对吗?@irrelephant Ah duh。Kuya的答案是好的,甚至更好,使用prepared语句来阻止SQLInjection@ShivanRaptor是的,这就是为什么我添加了关于如何使用准备好的语句进行保护的链接
:D