function fetch_by($table, $data_array, $return, $multi = false, $order_array = "") { if (!isset($this->tablefiles[$table])) { die($table . " does not exist!"); } $starttime = time() + microtime(); $result = array(); $f = fopen($this->folder . $this->tablefiles[$table], "r"); $id = 0; while ($l = fgets($f)) { if ($l[0] == '#') { continue; } if (substr($l, -1, 1) == "\n") { $l = substr($l, 0, -1); } if (substr($l, -1, 1) == "\r") { $l = substr($l, 0, -1); } $c = split(":", $l); $columngroup = array(); foreach ($this->table_columns[$table] as $columnname) { $columngroup[$columnname] = $this->unescape_string($c[$this->column_idx[$table . "." . $columnname]]); } $columngroup["id"] = $id++; if (is_array($data_array)) { $matches = true; reset($data_array); for ($a = 0; $a < count($data_array); $a++) { if ($columngroup[key($data_array)] != $data_array[key($data_array)]) { $matches = false; break; } next($data_array); } if ($matches) { $result[] = $columngroup; } } else { $result[] = $columngroup; } } fclose($f); $stoptime = time() + microtime(); if (is_array($order_array)) { reset($order_array); for ($a = 0; $a < count($order_array); $a++) { Flatfile::$sortname = key($order_array); if ($order_array[Flatfile::$sortname] != "DESC") { usort($result, "Flatfile::cmp1"); } else { usort($result, "Flatfile::cmp2"); } next($order_array); } } $total = round($stoptime - $starttime, 4); $this->overall_stats = $this->overall_stats + $total; if ($multi) { return $result; } else { if (isset($result[0])) { return $result[0]; } else { return array(); } } }