Last active
December 5, 2018 02:47
-
-
Save lcloss/e683f054063e63d14e312870fa0c59c3 to your computer and use it in GitHub Desktop.
Select com prepare + fetch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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