0

我正在尝试创建一个需要更改数据库密码的功能。我的问题是我可能在 sql 代码中出错。

我收到此错误消息: mysqli 类的对象无法询问已转换为 C:\WAMP\www\Connection\DB_Connection.php 中的字符串,第 32 行

它说我的 db_connection 有问题,但更相信我在处理程序中做错了什么

处理程序:

    public function ChangePassword($password,$username){
    var_dump($password,$username);
    $DBConnection = new DBConnection();
    $DBConnection -> Connect();
    $sql= "UPDATE user SET password=? where m_username=?";
    $stmt = $DBConnection -> prepare($sql);
    $stmt -> bind_param("ss",$m_password, $m_username);
    if ($stmt === FALSE) {
        //echoBr("prepare of '$sql' failed " .  $DBConnection -> error);
        return false;
    }
    $stmt -> execute();
    // ger resultet.
    $result = $stmt -> get_result();
    $stmt -> close();
    return false;

}

<?php
require_once ("settings.php");
require_once("Log.php");
class DBConnection {

private $m_mysqli = NULL;
public function Connect() {
    $log =  new Log(); 
    $password = "";
    $this -> m_mysqli = new mysqli(settings::DBhost, settings::DBroot,   

            settings::DBPassword, settings::DBdatabase);

    //utf 8
    $this -> m_mysqli -> set_charset("utf8");

    //kollar kopplingen till  databasen.
    if ($this -> m_mysqli -> connect_errno) {
        $log->LogMessage("Connect failed: $this->m_mysqli->connect_error");
        return false;
    } else {


        $log->LogMessage("har kontakt med databasen");

    }
    return true;
}

public function Prepare($sql) {
    $log =  new Log();
    $stmt = $this -> m_mysqli -> prepare($sql);
    if ($stmt === FALSE) {
        $log->LogMessage("Connect failed: $this->m_mysqli->connect_error");
        return false;
    }
    return $stmt;
}

public function Close() {
    $log =  new Log();
    $log->LogMessage("Close Connection");
    $this -> m_mysqli -> close();
}

public function error() {
    $log =  new Log();
    $wrong = "funktionen som heter error som ligger i db_c";
    $log->LogMessage("Close Connection");

    return $wrong;
}

}

4

0 回答 0