doubiaokai4998 2013-09-25 14:52
浏览 65
已采纳

使用codeigniter实现php-activerecord的问题

I am trying to implement php-active record based on the previous problem i had in the previous stackoverflow post setting up sparks with php-activerecord in codeigniter

ok, so i put that code in the constructor and my error vanished(phew).

but now on to testing that orm works. I created model called User.php in the models folder with the following code

<?php

class User extends ActiveRecord\Model {


}  

?> 

Then i went on to create a table in my database for testing wit php-activerecord to see if orm works. so i decided to have database called "spark" with a table called "users" using the following sql code below

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', '');

also my database.php is configured to match the table as follows:

$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 the database sorted, so i opened the welcome.php controller and add the following code into the index method as below

public function index()
    {


        $users = User::all();

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

i ran it in the browser and i got the following errors as below

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:     

so people let me know what i think the problem is

Thanks

Isaac

  • 写回答

1条回答 默认 最新

  • duannuochi3549 2013-09-25 15:29
    关注

    The problem is pretty clearly shown in the exception message:

    Message: Uncaught exception 'ActiveRecord\DatabaseException' with message 'ActiveRecord\MysqliAdapter not found!' in C:\xampp\htdocs\orm\sparks\php-activerecord\0.0.2\vendor\php-

    It's trying to load a mysqli adapter for the ActiveRecord library and not finding it. Either that library is not fully installed (missing optional mysqli module, perhaps) or the include path is not set up correctly to autoload its classes.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误