Skip to content

Instantly share code, notes, and snippets.

@lcloss
Last active December 5, 2018 02:47
Show Gist options
  • Save lcloss/e683f054063e63d14e312870fa0c59c3 to your computer and use it in GitHub Desktop.
Save lcloss/e683f054063e63d14e312870fa0c59c3 to your computer and use it in GitHub Desktop.
Select com prepare + fetch
$sql = "SELECT userID, nome, apelido FROM usuarios WHERE userID = ?";
$user = $_SESSION['user_portal'];
if ($stmt = mysqli->prepare($sql)) {
mysqli_stmt_bind_param($stmt, "i", (int)$user);
/* execute query */
mysqli_stmt_execute($stmt);
/* bind result variables */
mysqli_stmt_bind_result($stmt, $userid, $nome, $apelido);
/* fetch value */
mysqli_stmt_fetch($stmt);
echo "ID: " . $userid;
echo "Nome: " . $nome;
echo "Apelido: " . $apelido;
} else {
die('Falha no banco.');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment