我正在尝试基于我在之前的stackoverflow帖子中遇到的上一个问题来实现php-active记录 setting up sparks with php-activerecord in codeigniter
好的,所以我把那些代码放在构造函数中,我的错误就消失了(phew)。
但现在测试那个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:
所以人们让我知道我认为问题是什么
谢谢
艾萨克
答案 0 :(得分:1)
问题清楚地显示在异常消息中:
消息:未捕获异常'ActiveRecord \ DatabaseException',消息'找不到ActiveRecord \ MysqliAdapter!'在C:\ xampp \ htdocs \ orm \ sparks \ php-activerecord \ 0.0.2 \ vendor \ php -
它正在尝试为ActiveRecord库加载mysqli适配器而不是找到它。该库未完全安装(可能缺少可选的mysqli模块),或者未正确设置包含路径以自动加载其类。
答案 1 :(得分:-1)
PHPActiveRecord 建立在 PDO 之上,而不是 mysqli。该库不支持 mysqli。您看到此错误消息的原因是您已指定 'dbdriver' => 'mysqli'
但 PDO 没有 mysqli 驱动程序,也没有您尝试使用的此库。
要修复错误,只需指定 mysql
作为驱动程序。
'dbdriver' => 'mysql'