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 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器