Ejemplo n.º 1
0
 /**
  * Check if record exists in the database.
  *
  * Used for checking if a value already exists in the database.
  * Ex.: username, Partner ID
  *
  * @param mixed $values Column value
  * @param mixed $type Table column name
  * @param string $condition
  * @return boolean TRUE on success and FALSE on failure
  */
 public static function checkExists($values, $type = 'username', $condition = 'AND')
 {
     if (is_array($values) && is_string($type) && $condition == 'OR') {
         $sqlAdd = $type . '=';
         $sqlAdd .= implode(' ' . $condition . ' ' . $type . '=', array_map(array('Db_MySQL', 'filterStaticData'), $values));
     } else {
         if (is_array($values) && is_array($type)) {
             if (count($values) == count($type)) {
                 $sqlAddArray = array();
                 foreach ($values as $key => $value) {
                     $sqlAddArray[] = $type[$key] . '=' . Db_MySQL::filterStaticData($value);
                 }
                 $sqlAdd = implode(' ' . $condition . ' ', $sqlAddArray);
             } else {
                 return false;
             }
         } else {
             $sqlAdd = $type . '=' . Db_MySQL::filterStaticData($values);
         }
     }
     $sql = "SELECT ?f FROM ?f WHERE {$sqlAdd}";
     self::getDB()->query($sql, static::$idField, static::$table_name);
     return self::getDB()->numRows() > 0 ? true : false;
 }