public static function insert($values = []) { // Getting current rows in database if (Compose::prepared()) { if (array_key_exists(Compose::table(), Compose::databaseTableRows())) { // Checking if there is any rows in table, if there is then... $currentRows = Database::encodeDatabaseTableRows(Compose::table(), Compose::databaseTableRows()); //new Compile($currentRows); $seperateCurrentRows = implode("\n", $currentRows); } // Getting current rows and adding the new one $addRow = Compose::databaseTableRows(); $addRow[Compose::table()][] = array_combine(Compose::databaseTableColumns()[Compose::table()], $values); Initialize::data($addRow); new Compile($addRow); $encodeAddRow = Database::encodeDatabaseTableRows(Compose::table(), Compose::data()); $seperateEncodedAddRow = implode("\n", $encodeAddRow); new Compile($seperateEncodedAddRow); new Compile(Compose::databaseTableColumns()); $addRowTable = "|" . Compose::table() . "{\n\n" . Compose::databaseCode()["inTableColumns"][Compose::table()] . "\n\n" . $seperateEncodedAddRow . "\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"); } }
public static function encodeDatabaseTableRows($table, $data) { $tableRows = $data; new Compile($tableRows); new Compile(Compose::databaseTableColumns()); if (!empty($data)) { foreach ($tableRows[$table] as $key => $value) { echo $key . '<br>'; $new[] = implode('"."', $tableRows[$table][$key]); } foreach ($new as $key => $value) { $newer[] = $table . '["' . $value . '"]:'; } new Compile($new); /* for($i=0;$i<count($tableRows[$table]);$i++){ $new[] = implode('"."', $tableRows[$table][$i]); $newer[] = $table . '["' . $new[$i] . '"]:'; } */ new Compile($new); new Compile($newer); } return $newer; }