gpt4 book ai didi

PHP - 在 PHP 中比较分解的单词与 mysql varchar

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

如何在 PHP 中比较分解的单词和 mysql varchar?
这段代码产生了我想要的,但它也给出了这个错误

veranderenwachtwoordjij
fatal error :在非对象上调用成员函数 fetch_assoc()......

$word = "Also, to be safe, change your password regularly... you don't have to be obsessive about it: every three hours or so should be enough. And because erring on the side of caution is always a good idea, fake your own suicide and change your identity at least once a year.";

$pieces = explode(" ", $word);

$x = 0;
while($x < word_count($word)) { // word count function returns int (51)
$aPiece = $pieces[$x]; // change $pieces[$x] to 'you' and then it works
$result = $conn->query("SELECT * FROM dict WHERE english='$aPiece'");

$z = 0;
while($z < $num_result) // $num_result returns amount of rows in database
{
$row = $result->fetch_assoc(); //error line is here
echo stripslashes($row['dutch']);
$z++;
}

$x++;
}

最佳答案

我猜问题出在你的测试句子中的don:你忘记使用mysql_real_escape_string这样的函数转义引号。

例如:

$aPiece = mysql_real_escape_string($pieces[$x]);
$result = $conn->query("SELECT * FROM dict WHERE english='$aPiece'");

关于PHP - 在 PHP 中比较分解的单词与 mysql varchar,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1488744/

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