如何在 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/