PHP Classes
elePHPant
Icontem

PHP CodeIgniter Database Wrapper: Access database using CodeIgniter database library

Recommend this page to a friend!
  Info   View files Example   View files View files (98)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2019-07-08 (24 days ago) RSS 2.0 feedNot enough user ratingsTotal: 56 This week: 3All time: 9,520 This week: 76Up
Version License PHP version Categories
core-php-wrapper-lib 1.0Custom (specified...5PHP 5, Databases
Description Author

This package can access database using CodeIgniter database library.

It provides the database access library like CodeIgniter 3 framework but without having to use that framework. Currently it supports MySQL, MySQLi, PostgreSQL, ODBC, Microsoft SQL Server, SQLite, OCI8 databases.

The package can take an array of configuration options as parameter and initializes the main database access class object.

The database object can perform regular database access operations using a fluent interface to specify create, retrieve, update and delete operations as well functions to specify tables, fields, field values, conditions, etc..

Innovation Award
PHP Programming Innovation award nominee
July 2019
Nominee
Vote
CodeIgniter is a very popular framework used by many applications written in PHP.

Like many other frameworks it comes with a database abstraction library that allows accessing many different types of SQL based databases with the same function calls.

This package allows developers to use a database abstraction library without having to use the CodeIgniter framework as a whole.

Manuel Lemos
  Performance   Level  
Innovation award
Innovation award
Nominee: 1x

 

Details

CodeIgniter Database

Use the Database Library separately from CodeIgniter 3.

Installation

With Composer

"require": {
    "astute/CodeIgniterDB": "^1.0"
}

or with command line : composer require astute/CodeIgniterDB

Without Composer

You can also download it from Github, but no autoloader is provided so you'll need to register it with your own PSR-0 compatible autoloader.

Usage

<?php
use astute\CodeIgniterDB as CI;
$db_data = array(
	'dsn'	=> '',
	'hostname' => 'localhost',
	'username' => 'my_name',
	'password' => 'my_password',
	'database' => 'my_database',
	'dbdriver' => 'mysqli',
	'dbprefix' => '',
	'pconnect' => FALSE,
	'db_debug' => TRUE,
	'cache_on' => FALSE,
	'cachedir' => '',
	'char_set' => 'utf8',
	'dbcollat' => 'utf8_general_ci',
	'swap_pre' => '',
	'encrypt' => FALSE,
	'compress' => FALSE,
	'stricton' => FALSE,
	'failover' => array(),
	'save_queries' => TRUE
);
$oDb =& CI\DB($db_data);

For more information visit <a href="http://www.codeigniter.com/userguide3/database/index.html">CodeIgniter user guide</a>.

Custom option

I've added the possibility to give a mysql ressource to reuse a already opened connection. Thus to not multiply connections and to use this in parallel with legacy code and proceed to a migration step by step. Works only with the mysql driver ! Method 1 (Direct call)

<?php
use astute\CodeIgniterDB as CI;

$db_data = array(
	'dsn'	=> '',
	'hostname' => 'localhost',
	'username' => 'root',
	'password' => 'my_name',
	'database' => 'my_database',
	'dbdriver' => 'mysql',
	'dbprefix' => '',
	'pconnect' => FALSE,
	'db_debug' => TRUE,
	'cache_on' => FALSE,
	'cachedir' => '',
	'char_set' => 'utf8',
	'dbcollat' => 'utf8_general_ci',
	'swap_pre' => '',
	'encrypt' => FALSE,
	'compress' => FALSE,
	'stricton' => FALSE,
	'failover' => array(),
	'save_queries' => TRUE
);

$rDb = mysql_connect($db_data['hostname'], $db_data['root'], $db_data['password']);

$oDb =& CI\DB($db_data, null, $rDb);

Method 2 (Config file to call the object only) Config.php

<?php 
include('src/DB.php');
use astute\CodeIgniterDB as CI;
$db_data = array(
	'dsn'	=> '',
	'hostname' => 'localhost',
	'username' => 'my_name',
	'password' => 'my_password',
	'database' => 'my_database',
	'dbdriver' => 'mysqli',
	'dbprefix' => '',
	'pconnect' => FALSE,
	'db_debug' => TRUE,
	'cache_on' => FALSE,
	'cachedir' => '',
	'char_set' => 'utf8',
	'dbcollat' => 'utf8_general_ci',
	'swap_pre' => '',
	'encrypt' => FALSE,
	'compress' => FALSE,
	'stricton' => FALSE,
	'failover' => array(),
	'save_queries' => TRUE
);
$db =& CI\DB($db_data);

index.php Calling the database object by config.php file

<?php
include('config.php');
$result1 = $db->get('table_name')->row();

$result2 = $db->select('columName')->get('table_name')->row();.

$result3 = $db->select('columName')->where('columName',1)->get('table_name')->row();
print_r($result1);
echo '<br>';
print_r($result2);
echo '<br>';
print_r($result3);
  Files folder image Files  
File Role Description
Files folder imagesrc (8 files, 1 directory)
Plain text file config.php Conf. Configuration script
Plain text file index.php Example Example script
Plain text file LICENSE Lic. License text
Plain text file README.md Doc. Read Me

 Version Control Unique User Downloads Download Rankings  
 100%
Total:56
This week:3
All time:9,520
This week:76Up