我正在尝试根据上一个 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: