Php功能出现未声明

时间:2015-10-17 10:14:23

标签: php android mysql login web-hosting

我正在尝试登录android系统,当我尝试登录时,我在第74行收到错误"undefined function consigueResultado",但我宣布了该功能。有人知道什么可能是错的吗? 我使用000webhost可能与此错误有关吗?谢谢:))

 <?php
class DB_Functions {

    private $conn;

    // constructor
    function __construct() {
        require_once 'DB_Connect.php';
        // connecting to database
        $db = new Db_Connect();
        $this->conn = $db->connect();
    }

    // destructor
    function __destruct() {

    }

    public function consigueResultado( $stmt ) {
        $RESULT = array();
        $stmt->store_result();
        for ( $i = 0; $i < $stmt->num_rows; $i++ ) {
            $Metadata = $stmt->result_metadata();
            $PARAMS = array();
            while ( $Field = $Metadata->fetch_field() ) {
                $PARAMS[] = &$RESULT[ $i ][ $Field->name ];
            }
            call_user_func_array( array( $stmt, 'bind_result' ), $PARAMS );
            $stmt->fetch();
        }
        return $RESULT;
    }

    /**
     * Storing new user
     * returns user details
     */
    public function storeUser($name, $email, $password) {
        $uuid = uniqid('', true);
        $hash = $this->hashSSHA($password);
        $encrypted_password = $hash["encrypted"]; // encrypted password
        $salt = $hash["salt"]; // salt

        $stmt = $this->conn->prepare("INSERT INTO users(unique_id, name, email, encrypted_password, salt, created_at) VALUES(?, ?, ?, ?, ?, NOW())");
        $stmt->bindParam("sssss", $uuid, $name, $email, $encrypted_password, $salt);
        $result = $stmt->execute();
        $stmt->close();

        // check for successful store
        if ($result) {
            $stmt = $this->conn->prepare("SELECT * FROM users WHERE email = :email");
            $stmt->bindParam(':email', $email);
            $stmt->execute();
            $user = consigueResultado( $stmt );
            $stmt->close();

            return $user;
        } else {
            return false;
        }
    }

    /**
     * Get user by email and password
     */
    public function getUserByEmailAndPassword($email, $password) {

        $stmt = $this->conn->prepare("SELECT * FROM users WHERE email =:email");

        $stmt->bindParam(':email', $email);

        if ($stmt->execute()) {
            $user = consigueResultado( $stmt );
            $stmt->close();
            return $user;
        } else {
            return NULL;
        }
    }

    /**
     * Check user is existed or not
     */
    public function isUserExisted($email) {
        $stmt = $this->conn->prepare("SELECT email from users WHERE email = :email");

        $stmt->bindParam(':email', $email);
        $stmt->execute();

        $stmt->store_result();

        if ($stmt->num_rows > 0) {
            // user existed 
            $stmt->close();
            return true;
        } else {
            // user not existed
            $stmt->close();
            return false;
        }
    }

    /**
     * Encrypting password
     * @param password
     * returns salt and encrypted password
     */
    public function hashSSHA($password) {

        $salt = sha1(rand());
        $salt = substr($salt, 0, 10);
        $encrypted = base64_encode(sha1($password . $salt, true) . $salt);
        $hash = array("salt" => $salt, "encrypted" => $encrypted);
        return $hash;
    }

    /**
     * Decrypting password
     * @param salt, password
     * returns hash string
     */
    public function checkhashSSHA($salt, $password) {

        $hash = base64_encode(sha1($password . $salt, true) . $salt);

        return $hash;
    }
}
?>

5 个答案:

答案 0 :(得分:3)

在类内部我们必须使用$这个关键字来调用当前类的方法,例如你的方法调用应该是这样的

$this->consigueResultado( $stmt );

答案 1 :(得分:2)

类中的函数称为方法。方法并不存在于您的全局范围内,而是存在于您的对象范围内。仔细阅读Classes and Objects以更好地理解这一点。这样做的直接影响是您不应该尝试调用函数 consigueResultado,而是尝试这样的方法:

$user = $this->consigueResultado( $stmt );

答案 2 :(得分:2)

请在您可以调用该函数之后为该类创建一个对象。

 $obj = new Yourclassname();
 $obj->yourfunction();

喜欢这个......

答案 3 :(得分:0)

您可以尝试使用self调用该函数。试试这个self::consigueResultado(..);

答案 4 :(得分:0)

你为什么使用&#34;:email&#34;而不是&#34; s&#34;?

在哪里&#34;:电子邮件&#34;声明?