插入前插入单引号

时间:2012-12-07 05:06:04

标签: 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'  //This is expected
内爆应该怎么做?但我不知道怎么办?

1 个答案:

答案 0 :(得分:10)

试,

$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 Injection攻击,请阅读以下文章,了解如何从中学习,

其他来源