Yapı ve PHP ve javascript bir özlü json db kullanarak

0 Cevap php

Ben stackoverflow json hakkında birçok sorular gördüm. Çoğu cevapsız ya da temel fikir mevcut tekniklerden üzerinde naklediyor.

I want to build json db to use it in a easy way as a query usage. Like SELECT a WHERE a = $var;

Please your suggestions.
Thanks in advance.

    //sample jsondb
     {
      "name": "test",
      "columns": ["a", "b"],
      "rows":   [[1, 2],
                 [3, 4]]
      }


    $var = 3;
    //the aim is to use it easy as query usage
    SELECT a WHERE a = $var;

   //sample json object retrieved by PHP's json_encode() 
stdClass Object
    (
        [name] => test
        [columns] => Array
            (
                [0] => a
                [1] => b
            )

        [rows] => Array
            (
                [0] => Array
                    (
                        [0] => 1
                        [1] => 2
                    )

                [1] => Array
                    (
                        [0] => 3
                        [1] => 4
                    )

            )

    )

     //have the column a 
     $cols = array_flip($obj->columns);
     $col_a = $cols['a'];

     //filter to a=$var
     $rows_with_value_3 = array();
     foreach($obj->rows as $index => $rowvalues){

        foreach($rowvalues as $value){
            if($value[$col_a] == $var)
            $rows_with_value_3[$index] = $value[$col_a];
        }
     }

    //below the query string build functions
....

0 Cevap