Sunday, January 27, 2008

database to array

This is a small idea to fasten your web application, this is a backend process, so we are not concerned with the users internet speed, but the stability of the system relies in the hand of backend server and our scripts, what if we load whole database in n number of arrays, where n is equal to number of tables. Load database to the autoload.php file.
Here is a method to create array of a table from the database.
Create one file application/libraries/MyDbArray.php
Paste the following content to it.
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class MyDbArray

{

public $CI;

public $db_array=array();

function __construct()

{

$this->CI=& get_instance();

$query=$this->CI->db->get('ci_content');

$this->db_array=$query->result();

}

}

?>

Controller
<?php

class dbarray extends Controller

{

function __construct()

{

parent::Controller();

$this->load->library('MyDbArray');

}

function index()

{

print_r($this->mydbarray->db_array);

}

}

?>

No comments: