Пример #1
0
 public function tables()
 {
     // Collecting all table names and storing them (A)
     if (preg_match_all(Initialize::$replace["tableName"], Compose::databaseFile3(), $tableNameCode)) {
         new Compile($tableNameCode);
         $tableNames = $tableNameCode[1];
         Initialize::databaseTableNames($tableNames);
         new Compile($tableNames);
     } else {
         echo "ERROR 1";
     }
     echo Compose::databaseFile2();
     echo '<br><br><br>';
     new Compile((string) Compose::databaseFile3());
     echo '<br><br><br>';
     // For every table name..
     for ($i = 0; $i < count($tableNames); $i++) {
         // Check if code in database file is written correctly (B)
         if (preg_match_all(sprintf(Initialize::$replace["table"], $tableNames[$i], $tableNames[$i]), Compose::databaseFile3(), $tableCode)) {
             new Compile($tableCode);
             // Store data in arrays
             $tables[$tableNames[$i]] = $tableCode[0][0];
             $inTables[$tableNames[$i]] = $tableCode[1][0];
         } else {
             echo "noo";
         }
         // Initializing the code inside database table
         // Must initialize it here, if not, the collection of columns will not work.. [BUG]
         Initialize::databaseCode($inTables, "inTables");
         // Collecting the columns from table (C)
         if (preg_match_all(sprintf(Initialize::$replace["tableColumns"], $tableNames[$i], $tableNames[$i]), Compose::databaseCode()["inTables"][$tableNames[$i]], $columns)) {
             $columnsCode[$tableNames[$i]] = $columns[0][0];
             $column[] = $columns[1][0];
             $sortColumns[$tableNames[$i]] = preg_split(Initialize::$replace["seperate"], $column[$i]);
         } else {
             echo "He has not created columns..";
         }
         Initialize::databaseTableColumns($sortColumns);
         // Collecting all rows from tables (D)
         if (preg_match_all(sprintf(Initialize::$replace["tableRows"], $tableNames[$i]), Compose::undo(Compose::databaseCode()["inTables"][$tableNames[$i]]), $rows)) {
             new Compile($rows);
             $rowsCode[$tableNames[$i]] = $rows[0];
             $newRows[$tableNames[$i]] = $rows[1];
             foreach ($newRows[$tableNames[$i]] as $key => $value) {
                 $newRows2[$tableNames[$i]][] = preg_split(Initialize::$replace["seperate"], $newRows[$tableNames[$i]][$key]);
                 $newRows3[$tableNames[$i]][] = array_combine(Compose::databaseTableColumns()[$tableNames[$i]], $newRows2[$tableNames[$i]][$key]);
             }
         }
     }
     // End of loop
     //new Compile($newRows3);
     //new Compile($sortColumns);
     // Initializing the table code
     Initialize::databaseCode($tables, "tables");
     // Initializing the column code inside table
     Initialize::databaseCode($columnsCode, "inTableColumns");
     // Initializing the rows code inside table
     Initialize::databaseCode($rowsCode, "inTableRows");
     Initialize::databaseTableRows($newRows3);
     new Compile(Compose::databaseCode());
 }
Пример #2
0
 public static function update($column, $value)
 {
     if (Compose::prepared()) {
         $rows = Compose::databaseTableRows();
         if (array_key_exists(Compose::table(), Compose::where())) {
             // change this, it's a bug
             new Compile(Compose::where());
             $where = Compose::where();
             foreach ($where[Compose::table()] as $key => $values) {
                 $where[Compose::table()][$key][$column] = $value;
             }
             new Compile($where);
             $rows[Compose::table()] = array_replace($rows[Compose::table()], $where[Compose::table()]);
             $encodeRows = database::encodeDatabaseTableRows(Compose::table(), $rows);
             $seperateEncodedRows = implode("\n", $encodeRows);
             new Compile($seperateEncodedRows);
             new Compile($encodeRows);
             $addRowTable = "|" . Compose::table() . "{\n\n" . Compose::databaseCode()["inTableColumns"][Compose::table()] . "\n\n" . $seperateEncodedRows . "\n\n}." . Compose::table() . ";";
             $content = preg_replace(sprintf(Initialize::$replace["table"], Compose::table(), Compose::table()), $addRowTable, Compose::databaseFile3());
             new Compile($content);
             file_put_contents(Compose::databasePath(), $content);
             new Compile($rows);
         } else {
             // not using where, updating all rows
             foreach ($rows[Compose::table()] as $key => $values) {
                 $rows[Compose::table()][$key][$column] = $value;
             }
             new Compile($rows);
             $encodeRows = database::encodeDatabaseTableRows(Compose::table(), $rows);
             $seperateEncodedRows = implode("\n", $encodeRows);
             new Compile($seperateEncodedRows);
             new Compile($encodeRows);
             $addRowTable = "|" . Compose::table() . "{\n\n" . Compose::databaseCode()["inTableColumns"][Compose::table()] . "\n\n" . $seperateEncodedRows . "\n\n}." . Compose::table() . ";";
             $content = preg_replace(sprintf(Initialize::$replace["table"], Compose::table(), Compose::table()), $addRowTable, Compose::databaseFile3());
             new Compile($content);
             file_put_contents(Compose::databasePath(), $content);
         }
     } else {
         die("Prepare method not called");
     }
 }