class Users_Model extends Db_Model
{
private $id;
private $login;
private $password;
private $email;
private $first_name;
private $second_name;
function create(array $user_data)
{
$stmt = $this->db()->prepare("SELECT id FROM user WHERE login=? OR email=? LIMIT 1");
$stmt->bind_param("ss", $user_data['login'], $user_data['email']);
$stmt->execute();
$stmt->store_result();
$result = $stmt->num_rows;
$stmt->close();
if($result != 0)
{
echo 'fuck';
} else {
$this->setUserData($user_data);
$stmt = $this->db()->prepare("INSERT INTO user(login,password,email,first_name,second_name) VALUES (?, ?, ?, ?, ?)");
$stmt->bind_param('sssss', $this->login, $this->password, $this->email, $this->first_name, $this->second_name);
$stmt->execute();
$stmt->close();
}
}
private function setUserData(array $user_data)
{
$this->login = $user_data['login'];
$this->password = $user_data['password'];
$this->email = $user_data['email'];
$this->first_name = $user_data['first_name'];
$this->second_name = $user_data['second_name'];
}
}
Хотя код работает если нет проверки наличия login и email то есть без
if($result != 0)
{
echo 'fuck';
} else {
}