php 未找到活动记录\Myqli适配器

pb3skfrl  于 2023-03-07  发布在  PHP
关注(0)|答案(2)|浏览(141)

我正在尝试基于我在之前的堆栈溢出post setting up sparks with php-activerecord in codeigniter中遇到的问题来实现PHPActiveRecord
我把这些代码放到构造函数中,错误就消失了。
现在来测试orm的工作情况,我在models文件夹中创建了名为User.php的模型,代码如下

<?php

class User extends ActiveRecord\Model {

}  

?>

然后我继续在数据库中创建一个表,用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()
);

Dats数据库排序,所以我打开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:
5f0d552i

5f0d552i1#

PHPActiveRecord是建立在PDO之上的,而不是mysqli。这个库不支持mysqli。您看到这个错误消息的原因是您指定了'dbdriver' => 'mysqli',但是PDO没有mysqli驱动程序,您尝试使用的这个库也没有。
要修复此错误,只需指定mysql作为驱动程序。

'dbdriver' => 'mysql'
noj0wjuj

noj0wjuj2#

这个问题在异常消息中非常清楚地显示出来:
消息:C:\xampp\htdocs\orm\sparks\php-activerecord\0.0.2\vendor\php-中未捕获异常“活动记录\数据库异常”,并显示消息“未找到活动记录\MysqliAdapter!”
它试图为ActiveRecord库加载mysqli适配器,但没有找到。可能是该库没有完全安装(可能是缺少可选的mysqli模块),或者包含路径没有正确设置以自动加载其类。

相关问题