找不到 ActiveRecord\MysqliAdapter

Posted

技术标签:

【中文标题】找不到 ActiveRecord\\MysqliAdapter【英文标题】:ActiveRecord\MysqliAdapter not found找不到 ActiveRecord\MysqliAdapter 【发布时间】:2013-10-01 05:50:26 【问题描述】:

我正在尝试根据我在上一篇 Stack Overflow 帖子中遇到的问题来实现 phpActiveRecord setting up sparks with php-activerecord in codeigniter

我将该代码放入构造函数中,我的错误消失了(唷)。

但现在开始测试 orm 的工作原理。我使用以下代码在模型文件夹中创建了名为 User.php 的模型

<?php

class User extends ActiveRecord\Model 


  

?> 

                                    

然后我继续在我的数据库中创建一个表来测试 wit php-activerecord 以查看 orm 是否有效。 所以我决定使用下面的 SQL 代码创建一个名为“spark”的数据库和一个名为“users”的表

CREATE TABLE IF NOT EXISTS `users` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `username` varchar(32) NOT NULL,
  `password` varchar(32) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;

--
-- Dumping data for table `users`
--

INSERT INTO `users` (`id`, `username`, `password`) VALUES
(1, 'shawn', ''),
(2, 'justin', '');

另外我的database.php配置如下表匹配:

$db['default'] = array(
    'dsn'   => '',
    'hostname' => 'localhost',
    'username' => 'root',
    'password' => '',
    'database' => 'spark',
    'dbdriver' => 'mysqli',
    'dbprefix' => '',
    'pconnect' => TRUE,
    'db_debug' => TRUE,
    'cache_on' => FALSE,
    'cachedir' => '',
    'char_set' => 'utf8',
    'dbcollat' => 'utf8_general_ci',
    'swap_pre' => '',
    'autoinit' => TRUE,
    'encrypt' => FALSE,
    'compress' => FALSE,
    'stricton' => FALSE,
    'failover' => array()
);

对数据库进行排序,所以我打开了welcome.php控制器并将以下代码添加到索引方法中,如下所示

public function index()
    
        

        $users = User::all();

        echo "<pre>";
        print_r($users);
      

我在浏览器中运行它,我得到以下错误如下

Fatal error: Uncaught exception 'ActiveRecord\DatabaseException' with message 'ActiveRecord\MysqliAdapter not found!' in C:\xampp\htdocs\orm\sparks\php-activerecord\0.0.2\vendor\php-
activerecord\lib\Connection.php:127 Stack trace: #0 C:\xampp\htdocs\orm\sparks\php-activerecord\0.0.2\vendor\php-activerecord\lib\Connection.php(98):
ActiveRecord\Connection::load_adapter_class('mysqli') #1 C:\xampp\htdocs\orm\sparks\php-activerecord\0.0.2\vendor\php-activerecord\lib\ConnectionManager.php(33):
ActiveRecord\Connection::instance('mysqli://root:@...') #2 C:\xampp\htdocs\orm\sparks\php-activerecord\0.0.2\vendor\php-activerecord\lib\Table.php(103):
ActiveRecord\ConnectionManager::get_connection(NULL) #3 C:\xampp\htdocs\orm\sparks\php-activerecord\0.0.2\vendor\php-activerecord\lib\Table.php(80):
ActiveRecord\Table->reestablish_connection(false) #4 C:\xampp\htdocs\orm\sparks\php-activerecord\0.0.2\vendor\php-activerecord\lib\Table.php(61):
ActiveRecord\Table->__construct('User') #5 C:\xampp\htdocs\orm\sparks\php-activerecord\0.0.2\ve in C:\xampp\htdocs\orm\sparks\php-activerecord\0.0.2\vendor\php-activerecord\lib\Connection.php on line 127


A PHP Error was encountered

Severity: Error

Message: Uncaught exception 'ActiveRecord\DatabaseException' with message 'ActiveRecord\MysqliAdapter not found!' in C:\xampp\htdocs\orm\sparks\php-activerecord\0.0.2\vendor\php-
activerecord\lib\Connection.php:127 Stack trace: #0 C:\xampp\htdocs\orm\sparks\php-activerecord\0.0.2\vendor\php-activerecord\lib\Connection.php(98):
ActiveRecord\Connection::load_adapter_class('mysqli') #1 C:\xampp\htdocs\orm\sparks\php-activerecord\0.0.2\vendor\php-activerecord\lib\ConnectionManager.php(33):
ActiveRecord\Connection::instance('mysqli://root:@...') #2 C:\xampp\htdocs\orm\sparks\php-activerecord\0.0.2\vendor\php-activerecord\lib\Table.php(103):
ActiveRecord\ConnectionManager::get_connection(NULL) #3 C:\xampp\htdocs\orm\sparks\php-activerecord\0.0.2\vendor\php-activerecord\lib\Table.php(80):
ActiveRecord\Table->reestablish_connection(false) #4 C:\xampp\htdocs\orm\sparks\php-activerecord\0.0.2\vendor\php-activerecord\lib\Table.php(61): 
ActiveRecord\Table->__construct('User') #5 C:\xampp\htdocs\orm\sparks\php-activerecord\0.0.2\ve

Filename: lib/Connection.php

Line Number: 127

Backtrace:     

【问题讨论】:

【参考方案1】:

PHPActiveRecord 建立在 PDO 之上,而不是 mysqli。这个库不支持 mysqli。您看到此错误消息的原因是您指定了'dbdriver' =&gt; 'mysqli',但 PDO 没有 mysqli 驱动程序,您尝试使用的库也没有。

要修复错误,只需将mysql 指定为驱动程序。

'dbdriver' => 'mysql'

【讨论】:

【参考方案2】:

异常消息中非常清楚地显示了问题:

消息:未捕获的异常 'ActiveRecord\DatabaseException' 带有消息 'ActiveRecord\MysqliAdapter not found!'在 C:\xampp\htdocs\orm\sparks\php-activerecord\0.0.2\vendor\php-

它试图为 ActiveRecord 库加载一个 mysqli 适配器,但没有找到它。该库未完全安装(可能缺少可选的 mysqli 模块)或包含路径未正确设置以自动加载其类。

【讨论】:

我只是做人并通过作曲家安装活动记录,以便我可以正确自动加载它 你解决了吗?我在升级 Codeigniter 版本时遇到了同样的问题

以上是关于找不到 ActiveRecord\MysqliAdapter的主要内容,如果未能解决你的问题,请参考以下文章

java 枚举 找不到符号

bat系统找不到指定文件怎么办?

java package找不到符号

SpringBoot报找不到 dao 问题

ubuntu20.04找不到start命令

找不到名为“my”的模块。找不到名为“mycontroller”的控制器