无法在mongodb中保存PHP对象 [英] unable to save PHP objects in mongodb
问题描述
在保存对象时获取不允许使用零长度密钥"致命错误.
Getting 'zero-length keys are not allowed' FATAL error while saving object.
是因为存在__construct()吗?
Is it due to presence of __construct() ?
我相信save()方法中允许使用PHP对象.
I believe PHP object is allowed in 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);
致命错误:未捕获的异常"MongoException",消息为不允许使用零长度密钥,您是否在$中使用了双引号?"在/var/www/html/index.php:105中的堆栈跟踪:#0/var/www/html/index.php(105):MongoCollection-> save(Object(Address))#1 {main}抛出于/var/www/html/index.php,第105行
Fatal error: Uncaught exception 'MongoException' with message 'zero-length keys are not allowed, 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} thrown in /var/www/html/index.php on line 105
推荐答案
嗯,您如何期望mongo读取您的 private 类变量.
Umm, how do you expect mongo to read your private class variables.
这篇关于无法在mongodb中保存PHP对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!