PHP Classes

File: test/index.php

Recommend this page to a friend!
  Classes of Peter   Storage Class   test/index.php   Download  
File: test/index.php
Role: Example script
Content type: text/plain
Description: Example script
Class: Storage Class
Manipulate data in arrays and store it in files
Author: By
Last change: 1.add transaction/rollback/commit
2.add get last insert id
1.write cross storage join test code
2.fix join key is numberic zero then return false
3.fix charset not set can't connect to database
4.add timeout for memcache
5.add database server on runtime
6.add memcache server on runtime
7.rename mmcache method name search to get
8.rename mmcache method name update to set
9.rename mmcache method name insert to add
10.renmae mmcache method name remove to delete
Merge branch 'master' of github.com:teed7334-restore/storage

Conflicts:
README.md
Date: 8 years ago
Size: 2,751 bytes
 

Contents

Class file image Download
<?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';
}