function command(&$path, $cmds) { $id = ""; if (count($cmds) == 3) { $class = $cmds[1]; $id = $cmds[2]; } if (count($cmds) == 2) { $id = $cmds[1]; if (count($path) > 0) { $class = $path[0]; } else { return; } } if (count($cmds) == 1) { if (count($path) > 0) { $class = $path[0]; } else { return; } } $cols = $this->colums[$class]; if ($id != "") { $res = $this->con->query("SELECT * FROM `{$class}` WHERE id = {$id}")->fetch(\PDO::FETCH_ASSOC); } else { $res = $this->con->query($this->buildQuery("SELECT * ", $path))->fetch(\PDO::FETCH_ASSOC); } if ($res != "") { $items = []; } foreach ($cols as $key) { $val = $res[$key]; if (is_array($val)) { $val = "[" . implode(',', $val) . "]"; } $items[] = ['attribute' => $key . ': ', 'value' => $val]; } \CliWrapper\CliHelper::prettyPrint($items, '.', 10, [STR_PAD_RIGHT, STR_PAD_LEFT]); }
function command(&$path, $cmds) { $results = $this->con->query($this->buildQuery("SELECT * ", $path)); array_shift($cmds); if (count($path > 0)) { $keys = $cmds; if (count($keys) == 0) { $keys = array_slice($this->colums[$path[0]], 0, 5); } $i = 0; $items = []; while ($r = $results->fetch(\PDO::FETCH_ASSOC)) { $i++; reset($keys); $row = []; foreach ($keys as $key) { if ($key != "") { try { $val = $r[$key]; if (is_array($val)) { $out = '["' . implode('","', $val) . '"]'; } else { if (is_numeric($val)) { $out = $val; } else { $out = '"' . $val . '"'; } } $row[$key] = $out; } catch (Exception $e) { echo "field does not exist"; } } } $items[] = $row; } \CliWrapper\CliHelper::prettyPrint($items, ' '); } }