Php 致命错误:对非对象调用成员函数bind_param()(我的情况与所有重复的情况不同)

Php 致命错误:对非对象调用成员函数bind_param()(我的情况与所有重复的情况不同),php,database,Php,Database,我正试图更新我的数据库中某一行的某些字段,该行由电子邮件定义,但无论我做什么,都会出现此错误: 致命错误:在C:\wamp\www\android\u login\u api\include\DB\u Functions.php的第63行对非对象调用成员函数bind\u param() 这是我用来做这件事的PHP代码: <?php ini_set ( 'display_errors', 'On' ); class DB_Functions { private $conn; // c

我正试图更新我的数据库中某一行的某些字段,该行由电子邮件定义,但无论我做什么,都会出现此错误:

致命错误:在C:\wamp\www\android\u login\u api\include\DB\u Functions.php的第63行对非对象调用成员函数bind\u param()

这是我用来做这件事的PHP代码:

<?php
ini_set ( 'display_errors', 'On' );
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, $latitude, $longitude, $userType) {
    $uuid = uniqid ( '', true );
    $hash = $this->hashSSHA ( $password );
    $encrypted_password = $hash ["encrypted"]; // encrypted password
    $salt = $hash ["salt"]; // salt

    $service = "none";
    $rate = "none";
    $rated_clients = "none";

    $stmt = $this->conn->prepare ( "INSERT INTO users(unique_id, name, email, encrypted_password, latitude, longitude, userType, salt, service, rate, rated_clients, created_at) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, NOW())" );
    $stmt->bind_param ( "sssssssssss", $uuid, $name, $email, $encrypted_password, $latitude, $longitude, $userType, $salt, $service, $rate, $rated_clients );
    $result = $stmt->execute ();
    $stmt->close ();
    var_dump ( $result );
    // 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 ();
        var_dump ( $user );
        echo '</pre>';

        return $user;
    } else {

        return null;
    }
}

/**
 * Storing data
 * returns data details
 */
public function storeData($email, $service, $rate, $rated_clients) {
    $stmt = $this->conn->prepare ( "UPDATE users SET service = ? , rate = ? , rated_clients = ? WHERE email = ? " );
    $stmt->bind_param ( 'ssss', $service, $rate, $rated_clients, $email );
    var_dump ( $stmt->execute () );

    if ($stmt->execute ()) {
        $data = $stmt->get_result ()->fetch_assoc ();
        $stmt->close ();
        echo '</pre>';
        var_dump ( $data );
        return $data;
    } else {
        return NULL;
    }
}

/**
 * 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 ();
        $salt = $user ["salt"];
        $hash = $this->checkhashSSHA ( $salt, $password );
        if ($hash == $user ["encrypted_password"]) {
            return $user;
        } else {
            return NULL;
        }
    } 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;
}
}
?>

更改此选项:

$stmt = $this->conn->prepare ( "UPDATE users SET service = ? , SET rate = ? , SET rated_clients = ? WHERE email = ? " );
将是:

$stmt = $this->conn->prepare ( "UPDATE users SET service = ? , rate = ? , rated_clients = ? WHERE email = ? " );

很好,现在我得到了这个:(!)致命错误:在C:\wamp\www\android\u login\u api\include\DB\u Functions.php第67行调用非对象上的成员函数fetch_assoc(),我必须查看
DB_Functions.php
,我希望您有一个SQL语法错误这一行67$data=$stmt->get_result()->fetch_assoc();您根本不需要这一行,因为操作是
UPDATE
not
SELECT
。如果要检索受影响的行,可以使用
$stmt->受影响的行@wajeeh ok我确实返回了$stmt->受影响的行;但是它返回的是一些东西而不是一个对象。。。你认为发生了什么事?