예제 #1
0
 /**
  * Builds final query string, returns single array with both query string and query data
  */
 public function build()
 {
     $build = [];
     $tables = implode(", ", $this->_tables);
     $columns = !empty($this->_columns) ? implode(", ", $this->_columns) : "*";
     if (!empty($this->_explain)) {
         $build[] = "EXPLAIN";
     }
     if (!empty($this->_type)) {
         $build[] = $this->_type;
     }
     if ($this->_type === "SELECT") {
         $build[] = $columns . " FROM " . $tables;
     }
     if ($this->_type === "INSERT" || $this->_type === "REPLACE") {
         $build[] = "INTO " . $tables . " (" . implode(", ", $this->_fields) . ") VALUES (" . implode(", ", $this->_keys) . ")";
     }
     if ($this->_type === "UPDATE") {
         $build[] = $tables . " SET " . implode(", ", $this->_pairs);
     }
     if ($this->_type === "DELETE") {
         $build[] = "FROM " . $tables;
     }
     if (!empty($this->_joins)) {
         $build[] = implode(" ", $this->_joins);
     }
     if (!empty($this->_clauses)) {
         $build[] = "WHERE " . preg_replace("/(AND|OR)\$/u", "", implode(" ", $this->_clauses));
     }
     if (!empty($this->_group)) {
         $build[] = "GROUP BY " . implode(", ", $this->_group);
     }
     if (!empty($this->_order)) {
         $build[] = "ORDER BY " . implode(", ", $this->_order);
     }
     if (!empty($this->_limit)) {
         $build[] = "LIMIT " . implode(", ", $this->_limit);
     }
     $query = Sanitize::toSingleSpaces(implode(" ", $build));
     $data = $this->_data;
     $this->init();
     return [$query, $data];
 }
예제 #2
0
 /**
  * Contact array into inline string
  */
 public static function concat($value)
 {
     $output = "";
     if (is_array($value)) {
         foreach ($value as $entry) {
             $output .= " " . self::concat($entry);
         }
     } else {
         if (is_string($value) || is_numeric($value)) {
             $output .= " " . trim($value);
         }
     }
     return Sanitize::toSingleSpaces($output);
 }