I wanted to know if prepared query is as safe as one that is not prepared. Below are two examples, one for SELECT and one for UPDATE. First line is the not prepared and second is the prepared query.
SELECT examples:
$userDetails = $connection->query("SELECT * FROM Users WHERE Name='$username'")->fetch();
$userDetails = $connection->prepare('SELECT * FROM Users WHERE Name=?');
$userDetails->execute(array($username));
$userDetails = $userDetails->fetch();
UPDATE examples:
$query = $connection->query("UPDATE Users SET SessionID='$sessionID' WHERE Name='$username'")->execute();
$query = $connection->prepare("UPDATE Users SET SessionID=? WHERE Name=?");
$query->execute(array($sessionID, $username));
Should I use the long way of doing it or is the one that takes only one line to do worse?