将每个令牌保存在数据库的单独行中

时间:2015-07-27 09:40:05

标签: mysql token

我正在尝试将每个字符串标记保存在数据库的单独行中,以便我可以将其与其他字符串标记进行比较。

我正在使用PHP爆炸功能,我的语法是:

<?php
$someWords = "Please don't, blow me to pieces."; 

$wordChunks = explode(" ", $someWords);
for($i = 0; $i < count($wordChunks); $i++){
echo "Piece $i = $wordChunks[$i] <br />";

        $con = mysqli_connect("localhost","","","test");

    if (mysqli_connect_errno())
      {
      echo "Failed to connect to MySQL: " . mysqli_connect_error();
      }

  $sql="INSERT INTO TableName (file1) VALUES ('$wordChunks')";

if (!mysqli_query($con,$sql))
    {
        die('Error: ' . mysqli_error($con));
    }
    echo "1 record added successfully";

    mysqli_close($con);
}
?>

它提供此输出

it save the tokens in array not in string tokens

我想要这个输出

[I want that output[2]

1 个答案:

答案 0 :(得分:0)

使用MySQL mysqli_real_escape_string函数转义字符串,然后将其包含在查询中:

$sql = 'INSERT INTO TableName (file1) VALUES ('.mysqli_real_escape_string($wordChunks[$i]).')';