Ejemplo n.º 1
0
 public static function save($user_data)
 {
     $dbh = Db::get();
     try {
         $query = $dbh->prepare('INSERT INTO ' . static::tableName() . ' (login, password, email, sex, birth_date, other_info, picture) VALUES (:login, :password, :email, :sex, :birth_date, :other_info, :picture)');
     } catch (\PDOException $e) {
         echo "PDO Exception: ";
         var_dump($e->getMessage());
         die;
     }
     $query->bindValue(':login', $user_data['login']);
     $query->bindValue(':password', static::bcrypt($user_data['password']));
     $query->bindValue(':email', $user_data['email']);
     $query->bindValue(':sex', $user_data['sex']);
     $query->bindValue(':birth_date', $user_data['birth_date_year'] . '-' . $user_data['birth_date_month'] . '-' . $user_data['birth_date_day']);
     $query->bindValue(':other_info', $user_data['other_info']);
     $query->bindValue(':picture', isset($user_data['picture']) ? $user_data['picture'] : null);
     try {
         $query->execute();
     } catch (\PDOException $e) {
         echo "Error while saving user info: " . $e->getMessage();
     }
     $user_data['password'] = static::bcrypt($user_data['password']);
     return new UserModel($user_data);
 }
Ejemplo n.º 2
0
 public static function findOneByField($fieldName = 'id', $fieldValue)
 {
     $pdo = Db::get();
     try {
         $query = $pdo->prepare('SELECT * FROM ' . static::tableName() . ' AS tbl WHERE tbl.' . $fieldName . ' = :fieldvalue');
     } catch (\PDOException $e) {
         echo "PDO Exception: ";
         var_dump($e->getMessage());
         die;
     }
     $query->bindValue(':fieldvalue', $fieldValue);
     $query->execute();
     $user_row = $query->fetch(\PDO::FETCH_ASSOC);
     if (!$user_row) {
         return null;
         //no entries with this restrictions
     }
     foreach ($user_row as $index => $value) {
         $user_row[$index] = htmlentities($value);
     }
     return new static($user_row);
 }