我试图通过网站将CSV
文件插入数据库。该脚本工作正常,但不会将任何值插入到包含单引号的数据库中(例如“May's Flowers”)。我尝试了real_escape_string
函数和striplashes
函数,但它没有帮助。我甚至尝试将该变量作为字符串进行投射。有小费吗?代码的带单引号的CSV值被忽略
部分:
if($_FILES["file"]["size"] > 0)
{
$file = fopen($filename, "r");
//skip first line
fgetcsv($file); // first line wont show but neither the 3r
while (($getData = fgetcsv($file, 1000)) !== FALSE)
{
$sql = "INSERT into accounts (accountnumber, accountname, bookccy, date)
values ('$getData[0]','$getData[1]','$getData[2]','$getData[3]')";
$result = mysqli_query($conn, $sql);
使用[准备的语句(http://php.net/manual/en/mysqli.quickstart.prepared-statements.php)和[bind_param](http://php.net/manual/en /mysqli-stmt.bind-param.php)。这将绕过引用你自己的价值观的需要。 – aynber
你能举个例子吗? @aynber – noel293
阅读我链接的文档,所有的例子都在那里。 – aynber