object-oriented/blog-cms (bckp)/class/database/dao/UserDAO.php
/**
    * Method: select
    *
    * Selects user data from the database.
    *
    * @param string $columns: name of columns to be selected.
    * @param array  $whereColumns: name of columns used as conditions in WHERE clause.
    * @param array  $whereValues: value of columns used as conditions in WHERE clause.
    * @return User.
    *
    * Last Modified: Mar 18, 2019.
    */
select
Selects user data from the database.

@param string $columns: name of columns to be selected.
@param array  $whereColumns: name of columns used as conditions in WHERE clause.
@param array  $whereValues: value of columns used as conditions in WHERE clause.
@return User.


select Selects user data from the database . @param string $columns : name of columns to be selected . @param array $whereColumns : name of columns used as conditions in WHERE clause . @param array $whereValues : value of columns used as conditions in WHERE clause . @return User .
public function select($columns = "*", $whereColumns = "", $whereValues = "")
    {
        $whereClause = "";
        if (! empty($whereColumns)) {
            $whereClause .= " WHERE ";
            foreach ($whereColumns as $k => $v) {
                $whereClause .= QT_A . $v . QT_A . " = ";
                if (strpos($whereValues[$k], "MD5") !== false)
                    $whereClause .= $whereValues[$k] . " AND ";
                else
                    $whereClause .= QT . $whereValues[$k] . QT . " AND ";
            }
            $whereClause = substr($whereClause, 0, - strlen(" AND "));
        }
        $sql = "SELECT " . $columns . " FROM " . QT_A . $this->tableName . QT_A . $whereClause;
        $res = $this->query($sql);
        $user = null;
        if ($res->rowCount() > 0) {
            $user = new User(0, "", "", "");
            foreach ($res->fetchAll() as $userDB) {
                $user->setId($userDB["id"]);
                $user->setEmail($userDB["email"]);
                $user->setUsername($userDB["username"]);
                $user->setPassword($userDB["password"]);
            }
        }
        return $user;
    }
public function select ( $ columns = " * " , $ whereColumns = " " , $ whereValues = " " ) { $ whereClause = " " ; if ( ! empty ( $ whereColumns ) ) { $ whereClause .= "  WHERE  " ; foreach ( $ whereColumns as $ k => $ v ) { $ whereClause .= QT_A . $ v . QT_A . "  =  " ; if ( strpos ( $ whereValues [ $ k ] , " MD5 " ) !== false ) $ whereClause .= $ whereValues [ $ k ] . "  AND  " ; else $ whereClause .= QT . $ whereValues [ $ k ] . QT . "  AND  " ; } $ whereClause = substr ( $ whereClause , 0 , - strlen ( "  AND  " ) ) ; } $ sql = " SELECT  " . $ columns . "  FROM  " . QT_A . $ this -> tableName . QT_A . $ whereClause ; $ res = $ this -> query ( $ sql ) ; $ user = null ; if ( $ res -> rowCount ( ) > 0 ) { $ user = new User ( 0 , " " , " " , " " ) ; foreach ( $ res -> fetchAll ( ) as $ userDB ) { $ user -> setId ( $ userDB [ " id " ] ) ; $ user -> setEmail ( $ userDB [ " email " ] ) ; $ user -> setUsername ( $ userDB [ " username " ] ) ; $ user -> setPassword ( $ userDB [ " password " ] ) ; } } return $ user ; }
Method: select
 Selects user data from the database.
Method : select Selects user data from the database .
# echo $sql . "<br>"; die();