Ejemplo n.º 1
0
 public function translate($option)
 {
     $result = array();
     if (isset($option['event'])) {
         $event = self::translate_event($option['event'], $option['from']);
         if ($event == false) {
             exit('Error query');
         } else {
             $result[] = $event;
         }
     }
     if (isset($option['col'])) {
         $result[] = self::translate_col($option['col']);
     } else {
         if ($option['event'] === 'select' || $option['event'] === 'find') {
             $result[] = '*';
         }
     }
     if (isset($option['from']) && $option['event'] !== 'insert' && $option['event'] !== 'update') {
         $result[] = self::translate_from($option['from']);
     }
     if (isset($option['insert'])) {
         $result[] = self::translate_insert($option['insert']);
         return implode(' ', $result);
     }
     if (isset($option['update'])) {
         $result[] = self::translate_update($option['update']);
     }
     if (isset($option['where']) && $option['where'] !== null) {
         if (is_array($option['where'])) {
             self::$translate_where_var = array();
             $tWvar = self::translate_where($option['where']);
             $last_elem = $tWvar[count($tWvar) - 1];
             if ($last_elem === '||' || $last_elem === '&') {
                 array_pop($tWvar);
             }
             $result[] = 'WHERE ' . implode(' ', $tWvar);
         } else {
             $result[] = 'WHERE ' . $option['where'];
         }
     }
     if (isset($option['order'])) {
         $result[] = self::translate_order($option['order']);
     }
     if (isset($option['limit'])) {
         $result[] = self::translate_limit($option['limit']);
     }
     return implode(' ', $result);
 }