0

我正在尝试根据上一个 Stack Overflow 帖子中的问题来实现 PHPActiveRecord, 在 codeigniter 中使用 php-activerecord 设置火花

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

但是现在开始测试该 orm 的工作原理。我使用以下代码在模型文件夹中创建了名为 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()
);

对数据库进行排序,所以我打开了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:     
4

2 回答 2

0

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

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

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

于 2013-09-25T15:29:46.740 回答
-1

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

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

'dbdriver' => 'mysql'
于 2021-06-18T10:13:30.483 回答