我正在尝试创建一个我需要在数据库中更改密码的函数。我的问题是我可能在sql代码中出错了。
我收到此错误消息:类mysqli的对象无法在第32行的C:\ WAMP \ www \ Connection \ DB_Connection.php中请求转换为字符串
它说我的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;
}
}