๐Ÿ“ฆ jclapp23 / setfive_apply

๐Ÿ“„ UserTable.class.php ยท 42 lines
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42<?php 

require_once "DB.class.php";
require_once "User.class.php";

class UserTable {
	
	public static $TABLE_NAME = "user";
	
	/**
	 * @var DB
	 */
	private static $DB;
	
	/**
	 * Queries MySQL using the conditions in whereArray (columnName => value) and returns the first user, if found.
	 * If nothing is found, NULL is returned
	 * @param array $whereArray
	 * @return User
	 */
	public static function findOneBy( $whereArray ){
    $ret = current(self::$DB->selectWhere(self::$TABLE_NAME,$whereArray));
    if($ret)
    {
      
      $user = new User(self::$DB);
      $user->hydrate($ret);
      return $user;
    }

    return null;
	}
	
	/**
	 * Sets the DB property
	 * @param DB $db
	 */
	public static function setDB(DB $db){
		self::$DB=$db;
	}
	
}