gpt4 book ai didi

mysql - 将每个 token 保存在数据库中的单独行中

转载 作者:行者123 更新时间:2023-11-29 22:11:13 24 4
gpt4 key购买 nike

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

我正在使用 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]

最佳答案

在将字符串包含在查询中之前,使用 MySQL mysqli_real_escape_string 函数对字符串进行转义:

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

关于mysql - 将每个 token 保存在数据库中的单独行中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31649730/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com