php pdo FETCH_CLASS

时间:2013-12-12 21:46:15

标签: php pdo

为什么为我的值对象设置了一些其他属性。 (id,用户名,密码是公共属性,但0,1和2是未知的)(编辑:似乎fetch_class不工作,因为结果是一个数组)

Array
(
    [id] => 2
    [0] => 2
    [username] => john
    [1] => john
    [password] => $2y$10$xwkcBnXySe0jvHzFuN0OUeBvINQM33FUI0Ztnt0vNGgsQN/1ndGwe
    [2] => $2y$10$xwkcBnXySe0jvHzFuN0OUeBvINQM33FUI0Ztnt0vNGgsQN/1ndGwe
)

UserVO

namespace modules\positivo\model\valueObjects;

class UserVO {

    public $id;
    public $username;
    public $password;

    function __construct() {
    }
}

我在名称空间内的fetch类(PDO使用\

protected function getUserVO($username) {
    $statement = $this->connection->prepare("SELECT id, username, password FROM `user` WHERE username = :username AND suspended = 0 AND deleted = 0");
    $statement->setFetchMode(\PDO::FETCH_CLASS, 'UserVO');
    echo "<pre>";
    if($statement->execute(array('username' => $username))) {
        while($obj = $statement->fetch()) {
            print_r($obj);
            echo "<hr>";
        }
    } else {
        return null;
    }
}

0 个答案:

没有答案