2016-02-16 48 views
0

我做了一個android應用程序,發送數據到虛擬主機。我在我的應用的登錄部分遇到問題。當我仍然使用本地主機時,一切似乎都正常工作。然後,我將所有的php文件轉移到一個虛擬主機上。Json錯誤,當我的Android應用程序連接到網絡服務器

運行我LoginActivity.java,它給了我這個錯誤:

Fatal error: Call to undefined method mysqli_stmt::get_result() in /home/u186950481/public_html/android_login_api/include/DB_Functions.php on line 59

這裏是我的DB_Functions.php代碼:

<?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() { 

    } 

    /** 
    * 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->bind_param("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 = ?"); 
      $stmt->bind_param("s", $email); 
      $stmt->execute(); 
      $user = $stmt->get_result()->fetch_assoc(); 
      $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 = ?"); 

     $stmt->bind_param("s", $email); 

     if ($stmt->execute()) { 
      $user = $stmt->get_result()->fetch_assoc(); 
      $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 = ?"); 

     $stmt->bind_param("s", $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; 
    } 

} 

?> 

爲什麼這個方法mysqli_stmt::get_result()不確定?我錯過了什麼嗎?我沒有使用WAMP在我的本地主機上發生此錯誤。

+0

你在你的web服務器上使用不同的php版本嗎? – Sha7x

+0

5.5版本的服務器本地和虛擬主機 – seannnnnn

回答

0

mysqli_stmt :: get_result()要求mysqlnd

檢查here

嘗試在你的共享託管服務器的PHP版本更改爲5.3以上,如果可能的話,也可以使用bind_result並獲取代替

+0

感謝您的答覆。我檢查了我的cPanel中的php信息,mysqlnd啓用了我的php版本5.5。但它仍然不起作用 – seannnnnn

+0

嘗試使用bind_result http://php.net/manual/en/mysqli-stmt.bind-result.php –

+0

原諒我,如果我有點絕望,但你能教我如何做bind_result並獲取我的函數getUserByEmailAndPassword?請幫我,我是一個菜鳥在PHP。 – seannnnnn

相關問題