使用$ stmt-> get_result() - > fetch_assoc();调用未定义的方法mysqli_stmt :: get_result();

时间:2015-11-25 08:02:13

标签: php mysql

我在logcat中收到此错误:

  

致命错误:调用未定义的方法   mysqli_stmt :: get_result()在 ../ include / DB_Functions.php 上   第 42

我的DB_Functions.php中的代码是

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, $nric, $email, $mobileno, $address, $postalcode, $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, nric, email, mobileno, address, postalcode, encrypted_password, salt, created_at) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, NOW())");

    $stmt->bind_param("sssssssss", $uuid, $name, $nric, $email, $mobileno, $address, $postalcode, $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(); //(line 42)
        $stmt->close();

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

RegisterActivity.java

private void registerUser(final String name, final String nric, final String email, final String mobileno, final String address,final String postalcode,
                              final String password) {
    // Tag used to cancel the request
    String tag_string_req = "req_register";

    pDialog.setMessage("Registering ...");
    showDialog();

    StringRequest strReq = new StringRequest(Method.POST,
            AppConfig.URL_REGISTER, new Response.Listener<String>() {

        @Override
        public void onResponse(String response) {
            Log.d(TAG, "Register Response: " + response.toString());
            hideDialog();

            try {
                JSONObject jObj = new JSONObject(response);
                boolean error = jObj.getBoolean("error");
                if (!error) {
                    // User successfully stored in MySQL
                    // Now store the user in SQLite
                    String uid = jObj.getString("uid");

                    JSONObject user = jObj.getJSONObject("user");
                    String name = user.getString("name");
                    String nric = user.getString("nric");
                    String email = user.getString("email");
                    String mobileno = user.getString("mobileno");
                    String address = user.getString("address");
                    String postalcode = user.getString("postalcode");
                    String created_at = user.getString("created_at");

                    // Inserting row in users table
                    db.addUser(name, nric, email, mobileno, address, postalcode, uid, created_at);

                    Toast.makeText(getApplicationContext(), "User successfully registered. Try login now!", Toast.LENGTH_LONG).show();

                    // Launch login activity
                    Intent i = new Intent(
                            RegisterActivity.this,
                            InputVehicle.class);
                    startActivity(i);
                    finish();


                } else {

                    // Error occurred in registration. Get the error
                    // message
                    String errorMsg = jObj.getString("error_msg");
                    Toast.makeText(getApplicationContext(), errorMsg, Toast.LENGTH_LONG).show();
                }
            } catch (JSONException e) {
                e.printStackTrace();
                //nitta added
                Toast.makeText(getApplicationContext(), "Json error: " + e.getMessage(), Toast.LENGTH_LONG).show();
            }

        }
    }, new Response.ErrorListener() {

        @Override
        public void onErrorResponse(VolleyError error) {
            Log.e(TAG, "Registration Error: " + error.getMessage());
            Toast.makeText(getApplicationContext(),
                    error.getMessage(), Toast.LENGTH_LONG).show();
            hideDialog();
        }
    }) {

        @Override
        protected Map<String, String> getParams() {
            // Posting params to register url
            Map<String, String> params = new HashMap<String, String>();
            params.put("name", name);
            params.put("nric", nric);
            params.put("email", email);
            params.put("mobileno", mobileno);
            params.put("address", address);
            params.put("postalcode", postalcode);
            params.put("password", password);

            return params;
        }

    };

    // Adding request to request queue
    AppController.getInstance().addToRequestQueue(strReq, tag_string_req);
}

private void showDialog() {
    if (!pDialog.isShowing())
        pDialog.show();
}

private void hideDialog() {
    if (pDialog.isShowing())
        pDialog.dismiss();
}

我已经按照本教程: http://www.androidhive.info/2012/01/android-login-and-registration-with-php-mysql-and-sqlite/

我知道我需要安装mysqlnd,但我不知道如何:( 在这种情况下,我不知道如何使用获取和绑定结果,因为我对编程非常陌生。请帮忙!

最新更新:我使用了以下代码,没有更多错误。但是,JSON中没有解析信息。

  

$ user = $ stmt-&gt; fetch();

0 个答案:

没有答案