Answer the question
In order to leave comments, you need to log in
How to make such a function?
function mysqli_query_function($mysqli, $query, $vars) {
if(!isset($mysqli)) {
return FALSE;
}
if(!isset($query)) {
return FALSE;
}
if(!isset($vars)) {
return FALSE;
}
$stmt = $mysqli->prepare($query);
$stmt->bind_param('ssssssssss', $var[0], $var[1] .......);
$stmt->execute();
}
$mysqli = new mysqli($db_host, $db_user, $db_password, $db_name);
$query = 'UPDATE `users` SET `user` = ?, `id` = ? WHERE `login` = ?';
$vars['user'] = 'user';
$vars['id'] = 'id';
$vars['login'] = 'login';
mysqli_query_function($mysqli, $query, $vars);
if(!isset($mysqli)) {
return FALSE;
}
if(!isset($query)) {
return FALSE;
}
if(!isset($vars)) {
return FALSE;
}
$stmt = $mysqli->prepare('UPDATE `users` SET `user` = ?, `id` = ? WHERE `login` = ?');
$stmt->bind_param('sss', $var['user'], $var['id'], $var['login']);
$stmt->execute();
Answer the question
In order to leave comments, you need to log in
What only people do not go to not use PDO.
In the case of mysqli, you will have to store the key-position bind somewhere, but this is a road to nowhere.
What do you mean by "do generate bind_param()"?
It already exists php.net/manual/ru/mysqli-stmt.bind-param.php
$vars = [
'user'=>'Mike',
'id'=>123,
'login'=>'Agent M'
];
$types = str_pad('', count($vars), 's'); // генерируем строку 'sss' нужной длинны
$params = array_unshift($var, $types); // делаем ее первым параметром
$stmt = $mysqli->prepare('UPDATE `users` SET `user` = ?, `id` = ? WHERE `login` = ?');
$stmt->execute();
call_user_func_array ([$stmt, 'bind_param'], $params); // вызываем метод с этими параметрами
$stmt->execute();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question