出现未声明的 Php 函数

标签 php android mysql authentication 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;
    }
}
?>

最佳答案

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

$this->consigueResultado( $stmt );

关于出现未声明的 Php 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33185389/

相关文章:

php - 仅显示 mysql 中的唯一条目

php - HTTP 包装器不支持可写连接(CodeIgniter 问题?)

mysql - 如果客户已存在于同一个表中,尽管满足不同的条件,则排除 MySQL 查询的结果

PHP:如何在随机位置的字符串中添加随机字符

Android RemoteViews : setImageViewResource() vs setImageViewUri() vs setImageViewBitmap()

android - 盒装 SurfaceView

android - TabLayout 的不同标签宽度

php - Multi-Tenancy 数据库和一个模型 - MVC 和 Joomla

php - SQL 选择不区分大小写的文本,但不选择 Latex 函数名称

php打开修改并保存html文件