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?
Please follow below steps to integrate Codeigniter DB Active Record
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
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());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With