Failed to save PHP objects in mongodb
Obtaining "keys of zero length is not allowed" FATAL error while saving the object.
Is this due to the presence of __construct ()?
I believe the PHP object is resolved in the save () method.
class Address{
private $name;
private $company;
private $zip;
public function __construct($name,$company,$zip){
$this->name = $name;
$this->company = $company;
$this->zip = $zip;
}
}
$newAddress = new Address("james","google",678);
print_r($newAddress);
// Address Object ( [name:Address:private] => james [company:Address:private] =>
// google [zip:Address:private] => 678 )
$addresses->save($newAddress);
Fatal error: uncaught "MongoException" with message "zero-length keys" is invalid, did you use $ with double quotes? "in /var/www/html/index.php:105 Stack trace: # 0 / var / www / html / index.php (105): MongoCollection-> save (Object (Address)) # 1 {main} throw in /var/www/html/index.php on line 105
+3
source to share
1 answer