PHP Classes

Storage Class: Manipulate data in arrays and store it in files

Recommend this page to a friend!
     
  Info   Example   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 182 All time: 8,697 This week: 455Up
Version License PHP version Categories
storage-class 0.1BSD License5.3PHP 5, Databases, Files and Folders
Description 

Author

This package can manipulate data in arrays and store it in files.

It can take data in arrays and perform manipulation operations like databases such as searching, joining array records, ordering the results and return them split in pages of limited number of records.

The records of array data may be loaded and stored in files.

Picture of Peter
  Performance   Level  

 

Example

<?php
include_once('../config/config_setting.php');
$config = config_setting::get_config();
$main_path = $config['main_path'];
include_once(
"{$main_path}/index.php");

cross_storage_join();

function
cross_storage_join() {

   
$begin = microtime();

   
//crate object and load library
   
$storage = new index();
   
$storage->load('join');
   
$storage->load('order');
   
$storage->load('database');
   
$storage->load('mmcache');

   
//check permission data from memcache
   
$permission = $storage->mmcache->get('permission');

    if(
TRUE === empty($permission)) { //no permission data in memcache

        //check user data from memcache
       
$mysql = $storage->mmcache->get('user');

        if(
TRUE === empty($mysql)) { //no user data in memcache
           
$sql = "SELECT * FROM user";
           
$mysql = $storage->database->read_database($sql);

           
//write into memcache
           
$storage->mmcache->set_expire(3600);
           
$storage->mmcache->add('user', $mysql);
            echo
"user data from database <br />\n";
        }
        else {
            echo
"user data from memcache <br />\n";
        }

       
//check group data from memcache
       
$pgsql = $storage->mmcache->get('group');

        if(
TRUE === empty($pgsql)) { //no group data in memcache
           
$use = 'pgsql';
           
$host = '127.0.0.1';
           
$user = 'test';
           
$password = '12345678';
           
$database = 'test';
           
$storage->database->add_server($use, $host, $user, $password, $database);
           
$sql = "SELECT * FROM ugroup";
           
$pgsql = $storage->database->query($sql);
           
$pgsql = $pgsql->fetchAll(PDO::FETCH_ASSOC);

           
//write into memcache
           
$storage->mmcache->set_expire(3600);
           
$storage->mmcache->add('group', $pgsql);
            echo
"group data from database <br />\n";
        }
        else {
            echo
"group data from memcache <br />\n";
        }

       
$table_name = array('user' => 'group');
       
$storage->join->set_table_name($table_name);
       
$bind = array('group_id' => 'id');
       
$permission = $storage->join->inner_join($mysql, $pgsql, $bind);

       
//write into memcache
       
$storage->mmcache->set_expire(3600);
       
$storage->mmcache->add('permission', $permission);
        echo
"permission data from database <br />\n";
    }
    else {
        echo
"permission data from memcache <br />\n";
    }

    echo
"<br />\n";

   
//sort permission data
   
$orderBy = array('user.id' => 'ASC', 'user.account' => 'ASC');
   
$storage->order->order($permission, $orderBy);

   
print_r($permission);

    echo
"<br /><br />\n";

    echo
'Use ' . (microtime() - $begin) . ' microseconds';
}


Details

Storage

?????????????????????????Join??????????????

????????????PDO????????????????????????????????SQL??

[??]

1.??????????inner join, left join, right join, outer join, full join?

2.?????????????SQL?order by??

3.?????????????????

4.??????????

5.????????????????????

6.?????????memcache

7.?????????????????????????????????????????????????event page

8.??????????????????

[?????]

base - ???????

cache - ??????????

config - ???????

test - ????????????????

index.php - ???

[????]

?????test?????????????

[About author]

Name : Peter Cheng

Country : Taiwan

EMail 1 : teed7334@gmail.com

EMail 2 : teed7334@163.com


  Files folder image Files (53)  
File Role Description
Files folder imagebase (9 files)
Files folder imagecache (1 file)
Files folder imageconfig (4 files)
Files folder imagelibrary (1 directory)
Files folder imagetest (3 files, 9 directories)
Plain text file index.php Class Class source
Accessible without login Plain text file README.md Data Auxiliary data

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 100%
Total:182
This week:0
All time:8,697
This week:455Up