2

i can try to update the attempt to login in mongodb but it can showing error in php with my sql i can use this code:

$columns = "";
  foreach($toUpdate as $k => $v){
    $columns .= "$k = :$k, ";
  }
  $columns = substr($columns, 0, -2); // Remove last ","

  $sql = $this->dbh->prepare("UPDATE user  SET {$columns} WHERE id=:id");
  $sql->bindValue(":id", $user);
  foreach($toUpdate as $key => $value){
    $value = htmlspecialchars($value);
    $sql->bindValue(":$key", $value);
  }

  $sql->execute();

in this code it can display no.of attempt to login..but can write this code in php with mongodb it can showing error

$columns = "";
  foreach($toUpdate as $k => $v){
    $columns .= "$k = :$k, ";
  }
  $columns = substr($columns, 0, -2); // Remove last ","

                        $collection=user;//table name;
                        $set = array('$set' =>array(array($columns)));
                        $m->$collection->update(array(id=>$user),$set);

  foreach($toUpdate as $key => $value)
  {
      var_dump($toUpdate);
    $value = htmlspecialchars($value);
    $m->$collection->update(array(id=>$value),$set);

  }

i can try many way but it show error ....this is error

Uncaught exception 'MongoWriteConcernException' with message 'localhost:27017: Modifiers operate on fields but we found type array instead. For example: {$mod: {: ...}} not {$set: [ [ "attempt = :attempt" ] ]})

any one can know how to solve this

3
  • it can also showing same error ( Uncaught exception 'MongoWriteConcernException' with message 'localhost:27017: Modifiers operate on fields but we found type array instead. For example: {$mod: {<field>: ...}} not {$set: [ [ "attempt = :attempt" ] ]}) Commented Jun 22, 2017 at 12:57
  • i can try this way also: Commented Jun 22, 2017 at 12:57
  • $collection=$this->config['db']['table'];//table name; $set = array('$set' =>array(array($columns))); $this->dbh->$collection->update(array($this->config["db"]["columns"]["id"]=>$user),$set); Commented Jun 22, 2017 at 12:57

1 Answer 1

1

This error is given to you because you are passing an array of array to $set instead of an array of data:

$set = array('$set' =>array(array($columns)));

Try with this:

$set = array('$set' =>array($columns));
Sign up to request clarification or add additional context in comments.

1 Comment

it can also showing same error ( Uncaught exception 'MongoWriteConcernException' with message 'localhost:27017: Modifiers operate on fields but we found type array instead. For example: {$mod: {<field>: ...}} not {$set: [ [ "attempt = :attempt" ] ]})

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.