首页 > 编程语言 >PHP message: PHP Fatal error: Uncaught Error: Class 'Mongo' not found

PHP message: PHP Fatal error: Uncaught Error: Class 'Mongo' not found

时间:2023-03-15 10:35:34浏览次数:78  
标签:Exception Mongo MongoDB Driver mysqli found BSON PHP

brew + Nginx + PHP7 + MongoDB3.2.9 + Mongo-PHP_driver 1.40

搭好环境后写了个脚本:

<?php  
$connection = new Mongo();
?> 

通过网页访问,网页显示空白,查看nginx 的错误日志是:

"PHP message: PHP Fatal error:  Uncaught Error: Class 'Mongo' not found in /var/www/phpscripts/mongo.php:2

找不到Mongo这个类,
通过函数 get_extension_funcs 和get_declared_classes查看mongo提供的类名和函数名
print_r(get_extension_funcs('mongodb')); #看一下该扩展中提供了那些函数
print_r(get_declared_classes()); #看一下预定义类中是否有你需要(或相似)的类名

Array
(
    [0] => MongoDB\BSON\fromPHP
    [1] => MongoDB\BSON\toPHP
    [2] => MongoDB\BSON\toJSON
    [3] => MongoDB\BSON\fromJSON
)
Array
(
    [0] => stdClass
    [1] => Exception
    [2] => ErrorException
    [3] => Error
    [4] => ParseError
    [5] => TypeError
    [6] => ArithmeticError
    [7] => DivisionByZeroError
    [8] => Closure
    [9] => Generator
    [10] => ClosedGeneratorException
    [11] => DateTime
    [12] => DateTimeImmutable
    [13] => DateTimeZone
    [14] => DateInterval
    [15] => DatePeriod
    [16] => LogicException
    [17] => BadFunctionCallException
    [18] => BadMethodCallException
    [19] => DomainException
    [20] => InvalidArgumentException
    [21] => LengthException
    [22] => OutOfRangeException
    [23] => RuntimeException
    [24] => OutOfBoundsException
    [25] => OverflowException
    [26] => RangeException
    [27] => UnderflowException
    [28] => UnexpectedValueException
    [29] => RecursiveIteratorIterator
    [30] => IteratorIterator
    [31] => FilterIterator
    [32] => RecursiveFilterIterator
    [33] => CallbackFilterIterator
    [34] => RecursiveCallbackFilterIterator
    [35] => ParentIterator
    [36] => LimitIterator
    [37] => CachingIterator
    [38] => RecursiveCachingIterator
    [39] => NoRewindIterator
    [40] => AppendIterator
    [41] => InfiniteIterator
    [42] => RegexIterator
    [43] => RecursiveRegexIterator
    [44] => EmptyIterator
    [45] => RecursiveTreeIterator
    [46] => ArrayObject
    [47] => ArrayIterator
    [48] => RecursiveArrayIterator
    [49] => SplFileInfo
    [50] => DirectoryIterator
    [51] => FilesystemIterator
    [52] => RecursiveDirectoryIterator
    [53] => GlobIterator
    [54] => SplFileObject
    [55] => SplTempFileObject
    [56] => SplDoublyLinkedList
    [57] => SplQueue
    [58] => SplStack
    [59] => SplHeap
    [60] => SplMinHeap
    [61] => SplMaxHeap
    [62] => SplPriorityQueue
    [63] => SplFixedArray
    [64] => SplObjectStorage
    [65] => MultipleIterator
    [66] => ReflectionException
    [67] => Reflection
    [68] => ReflectionFunctionAbstract
    [69] => ReflectionFunction
    [70] => ReflectionGenerator
    [71] => ReflectionParameter
    [72] => ReflectionType
    [73] => ReflectionMethod
    [74] => ReflectionClass
    [75] => ReflectionObject
    [76] => ReflectionProperty
    [77] => ReflectionExtension
    [78] => ReflectionZendExtension
    [79] => SessionHandler
    [80] => __PHP_Incomplete_Class
    [81] => php_user_filter
    [82] => Directory
    [83] => AssertionError
    [84] => ZipArchive
    [85] => LibXMLError
    [86] => DOMException
    [87] => DOMStringList
    [88] => DOMNameList
    [89] => DOMImplementationList
    [90] => DOMImplementationSource
    [91] => DOMImplementation
    [92] => DOMNode
    [93] => DOMNameSpaceNode
    [94] => DOMDocumentFragment
    [95] => DOMDocument
    [96] => DOMNodeList
    [97] => DOMNamedNodeMap
    [98] => DOMCharacterData
    [99] => DOMAttr
    [100] => DOMElement
    [101] => DOMText
    [102] => DOMComment
    [103] => DOMTypeinfo
    [104] => DOMUserDataHandler
    [105] => DOMDomError
    [106] => DOMErrorHandler
    [107] => DOMLocator
    [108] => DOMConfiguration
    [109] => DOMCdataSection
    [110] => DOMDocumentType
    [111] => DOMNotation
    [112] => DOMEntity
    [113] => DOMEntityReference
    [114] => DOMProcessingInstruction
    [115] => DOMStringExtend
    [116] => DOMXPath
    [117] => PDOException
    [118] => PDO
    [119] => PDOStatement
    [120] => PDORow
    [121] => SimpleXMLElement
    [122] => SimpleXMLIterator
    [123] => XMLReader
    [124] => XMLWriter
    [125] => PharException
    [126] => Phar
    [127] => PharData
    [128] => PharFileInfo
    [129] => CURLFile
    [130] => finfo
    [131] => MongoDB\Driver\Command
    [132] => MongoDB\Driver\Cursor
    [133] => MongoDB\Driver\CursorId
    [134] => MongoDB\Driver\Manager
    [135] => MongoDB\Driver\Query
    [136] => MongoDB\Driver\ReadConcern
    [137] => MongoDB\Driver\ReadPreference
    [138] => MongoDB\Driver\Server
    [139] => MongoDB\Driver\BulkWrite
    [140] => MongoDB\Driver\WriteConcern
    [141] => MongoDB\Driver\WriteConcernError
    [142] => MongoDB\Driver\WriteError
    [143] => MongoDB\Driver\WriteResult
    [144] => MongoDB\Driver\Exception\LogicException
    [145] => MongoDB\Driver\Exception\RuntimeException
    [146] => MongoDB\Driver\Exception\UnexpectedValueException
    [147] => MongoDB\Driver\Exception\InvalidArgumentException
    [148] => MongoDB\Driver\Exception\ConnectionException
    [149] => MongoDB\Driver\Exception\AuthenticationException
    [150] => MongoDB\Driver\Exception\SSLConnectionException
    [151] => MongoDB\Driver\Exception\WriteException
    [152] => MongoDB\Driver\Exception\BulkWriteException
    [153] => MongoDB\Driver\Exception\ExecutionTimeoutException
    [154] => MongoDB\Driver\Exception\ConnectionTimeoutException
    [155] => MongoDB\BSON\Binary
    [156] => MongoDB\BSON\Javascript
    [157] => MongoDB\BSON\MaxKey
    [158] => MongoDB\BSON\MinKey
    [159] => MongoDB\BSON\ObjectID
    [160] => MongoDB\BSON\Regex
    [161] => MongoDB\BSON\Timestamp
    [162] => MongoDB\BSON\UTCDateTime
    [163] => mysqli_sql_exception
    [164] => mysqli_driver
    [165] => mysqli
    [166] => mysqli_warning
    [167] => mysqli_result
    [168] => mysqli_stmt
    [169] => SoapClient
    [170] => SoapVar
    [171] => SoapServer
    [172] => SoapFault
    [173] => SoapParam
    [174] => SoapHeader
    [175] => SQLite3
    [176] => SQLite3Stmt
    [177] => SQLite3Result
    [178] => XSLTProcessor
)

原来MongoDB的类名变成了: MongoDB\Driver\Manager
因此这样修改文件 :

$con     =  new  MongoDB\Driver\Manager( 'mongodb://127.0.0.1:27017' );
$query   =  new  MongoDB\Driver\Query([]);
$cursor  =  $con ->executeQuery( 'test.person' , $query ); #test id mongodb default database, person is created by ourself
$it      =  new  IteratorIterator( $cursor );
$it -> rewind ();
while  ( $doc = $it ->current()) {
     print_r( $doc );
     $it ->next();
     echo  '<br/>' ;
}

原文链接:https://blog.csdn.net/zhuxiaoping54532/article/details/52326149

标签:Exception,Mongo,MongoDB,Driver,mysqli,found,BSON,PHP
From: https://www.cnblogs.com/hefeng2014/p/17217568.html

相关文章

  • php 分组查询报错
    SQLSTATE[42000]:Syntaxerrororaccessviolation:1055Expression#3ofSELECTlistisnotinGROUPBYclauseandcontainsnonaggregatedcolumn'originthink.t......
  • Oracle 查询时报错ORA-00923: FROM keyword not found where expected
    Oracle查询时报错ORA-00923:FROMkeywordnotfoundwhereexpected,从字面上理解就是SQL语法错误缺少FROM关键字,下面简单说一下可能发生报错的几种情况:第一种查询语句......
  • python读取mongodb并写入文件
     #!/usr/bin/envpython#coding=utf-8frompymongoimportMongoClientimporttimefromdatetimeimportdatetimedefchaxun_data():##client=MongoCl......
  • C网络库mongoose
     官方链接:https://github.com/cesanta/mongoose[C++]-网络库mongoose简介_alwaysrun的博客-CSDN博客_c++mongooseMongoose-基于C的Web服务器介绍和使用-百度文库......
  • MongoDb集合改名
    publicbooleanmongoDbCollectionNameUpdate(StringoldName,StringnewName){/连接MongoDB数据库/MongoClientmongoClient=MongoClients.create(mongourl);MongoDa......
  • wsl+php开发环境配置
    记录下安装过程,方便后续安装一、安装wsl参考:https://zhuanlan.zhihu.com/p/466001838   1、尽管理员身份运行powershell,运行下面四条命令wsl--installdism.e......
  • php操作rabbitmq实例
    title:PHP使用RabbitMQ实例date:2021-03-2217:37:29tags:phpcategories:php消费者代码consumer.php <?php /** *CreatedbyPhpStorm. *User:wangyii.c......
  • uni-app+php:微信小程序登录:用code得到openid/unionid(hbuilderx 3.7.3)
    一,js代码:<template><view><buttonclass="login-wxpng"open-type="getUserInfo"@getuserinfo="xcxWxLogin">微信小程序登录......
  • Ubuntu22.10 使用命令安装 MongoDB6.0 并配置
     安装mongodbapt-getinstallgnupgwget-qO-https://www.mongodb.org/static/pgp/server-6.0.asc|apt-keyadd-echo"deb[arch=amd64,arm64]https://repo......
  • PHP WEB项目文件夹上传下载解决方案
    一、功能性需求与非功能性需求要求操作便利,一次选择多个文件和文件夹进行上传;支持PC端全平台操作系统,Windows,Linux,Mac支持文件和文件夹的批量下载,断点续传。刷新页面......