How to use database codeigniter class without codeIgniter MVC framework?

codeigniter, codeigniter-2, php

Solution

Please follow below steps to integrate Codeigniter DB Active Record

- Download latest codeigniter from https://codeigniter.com/

Copy below files

application/config/config.php
application/config/database.php

system/database/*

system/core/Common.php
system/core/Exceptions.php
system/core/Log.php

The directory structure is as above

- Add database connection details in `application/config/database.php`

Create db connection(connector.php) file

<?php
defined('DS') OR define('DS', DIRECTORY_SEPARATOR);
defined('EXT') OR define('EXT', '.php');
defined('ENVIRONMENT') OR define('ENVIRONMENT', 'development');

$dir_path = dirname(__FILE__) . DS;
defined('BASEPATH') OR define('BASEPATH', $dir_path . 'system' . DS);
defined('APPPATH') OR define('APPPATH', $dir_path . 'application' . DS);

function getDBConnector(){
    include_once(BASEPATH . "core/Common.php");
    include_once(BASEPATH . "core/Exceptions.php");
    require_once(BASEPATH . 'database/DB' . EXT);
    $conn = & DB();
    return $conn;
}    

$db = getDBConnector();

print_r($db->get('users')->result_array());

- Now include connector.php in your project and access DB object :)

Problem

My goal is to use the CodeIgniter database Class, but inside a plain PHP script. I don't want to use MVC structure for this. Can I use this database class WITHOUT using the CodeIgniter MVC pattern? If yes, how?

Original source