开发者

Problem with SQL query when calling a static function from another static function in the same class

I'm new to PHP, but not new to programming. I have a strange problem. It's such a simple thing, and I have the feeling the solution is simple also, but I tried for hours without luck.

I have a model class User which contains the following function:

public static function byUsername($username) {
    $row = DB::fetchOne('SELECT * FROM users WHERE username = ?', $username);
    if (!is_null($row)) {
        return new User($row);
    }
    return null;
}

It works as expected everywhere, returning a User object given the right username. Except in the User class itself: when I call the function with User::byUsername('a_valid_username'), or self::, from another st开发者_开发知识库atic function further down in the User class, the DB::fetchOne() function just returns null, no errors or exceptions.

What am I missing?


I don't see a problem inside of the byUsernam() method.

Perform

echo $username;

or

print_r( debug_backtrace() );

right at the beginning of byUsernam() to learn more of the called environment.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜