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

标签 php mysql

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

相关文章:

mysql - 从表中获取符合条件的学生的 SQL 查询错误

mysql - 错误 1215 : Can't add foreign key constraint (InnoDB)

php - PHP 中的 XML 输出 (UTF-8)

php - php中的json对象没有被读取

php - 无法从 PHP 上的 MySQL 响应中检索信息

MySQL group by 填补空白

php - 当您两次选择同一个表作为 a 和 b 时,如何在电子邮件中调用表名?

javascript - 使用 Ajax 单击按钮删除表行

mysql - 从四个表中进行 SQL 查询

MySQL多索引条件变慢?