Answer the question
In order to leave comments, you need to log in
Mysqli database query description in class?
I want to describe the processing of a request to the database in a class method.
function verifyUser($name) {
$query = "SELECT psw, user_group FROM users WHERE name = ?";
$stmt = $mysqli->stmt_init();
if ($stmt = $mysqli->prepare($query)) {
/* связываем параметры с метками */
$stmt->bind_param("s", $name);
/* запускаем запрос */
$stmt->execute();
/* связываем переменные с результатами запроса */
$stmt->bind_result($psw, $user_group);
/* получаем значения */
$stmt->fetch();
printf("login - %s, password - %s, user_group - %s", $name, $psw, $user_group);
/* закрываем запрос */
$stmt->close();
}
}
}
$name = $_POST["name"];
$auth = new Auth($name);
$auth->verifyUser($name);
Answer the question
In order to leave comments, you need to log in
$name = $_POST["name"];
$db = new mysqi();
$auth = new Auth($db);
$auth->verifyUser($name);
And where does $stmt? The error says that the stmt_init() method is not called on an object, that is, $mysqli is not an object.
The error says $mysqli is not an object.
function verifyUser($name) {
$query = "SELECT psw, user_group FROM users WHERE name = ?";
require_once path_to_mysqli_class //на случай если файл не в автолоудинге и еще не заинклюжен
$mysqli = new Mysqli();
$stmt = $mysqli->stmt_init();
...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question