Which of this is right and really safe?
Using prepared statements:
$stmt= $db->prepare("INSERT INTO books (title) VALUES (?)");
$booktitle=$_POST['booktitle'];
$stmt->bind_param('s', $booktitle);
$stmt->execute();
Or using escape function :
$unsafe_variable = $login;
$safe_variable = mysqli_real_escape_string($unsafe_variable);
$stm=mysqli_query($db,"SELECT post_amount FROM users WHERE login='" . $safe_variable . "'");
$stmone=mysqli_fetch_assoc($stm);
$stmtwo=implode($stmone);
echo($stmtwo);
Please, help to deal with it.