【发布时间】:2018-03-09 07:42:40
【问题描述】:
申请详情: 我正在开发一个 Web 应用程序,其中我使用 php 作为服务器端语言,使用 mongodb 作为数据库。我正在使用 php mongodb 库来连接 mongodb 数据库。
问题: 我可以使用 mongoDB 库从后端成功创建数据库连接。但是当我运行查找查询时,我收到以下错误消息:
致命错误:未捕获的异常 带有消息“命名空间”的“MongoDB\Driver\Exception\RuntimeException” 不能嵌入空字符 C:\wamp64\www\analytic_script\vendor\mongodb\mongodb\src\Operation\Find.php 180号线
谁能告诉我可能的解决方案。这是发生错误的find.php函数。
public function execute(Server $server)
{
$readPreference = isset($this->options['readPreference']) ? $this->options['readPreference'] : null;
**// Error is occuring at this line**
$cursor = $server->executeQuery($this->databaseName . '.' . $this->collectionName, $this->createQuery(), $readPreference);
if (isset($this->options['typeMap'])) {
$cursor->setTypeMap($this->options['typeMap']);
}
return $cursor;
}
【问题讨论】:
-
听起来
databaseName或collectionName之一为空,或者根据错误消息包含null(\0) 字符。 -
好的@KevinAdistambha,感谢您的cmets。在深入研究时,我发现 php mongodb 扩展与我正在使用的 mongo 包不兼容。当我升级扩展版本时,它可以完美运行。无论如何,谢谢。
标签: php mongodb mongodb-query