Skip to content

Instantly share code, notes, and snippets.

@andersonFaro9
Created November 9, 2014 20:08
Show Gist options
  • Save andersonFaro9/9d106bb115883fa82652 to your computer and use it in GitHub Desktop.
Save andersonFaro9/9d106bb115883fa82652 to your computer and use it in GitHub Desktop.
<?php
function conectar()
{
try {
$email = $_POST['email'];
$senha = $_POST['senha'];
$pdo = new \PDO('mysql:dbname=banco;host=localhost', 'root', 'root');
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = $pdo->prepare(
"SELECT * FROM usuarios WHERE email = '$email' AND senha = '$senha' "
);
$sql->bindValue("email:", $email);
$sql->bindValue("senha:", $senha);
$sql->execute();
if ($sql->rowCount() == 1) {
$dadosDoUsuario = $sql->fetch(PDO::FETCH_OBJ);
$_SESSION['nomeUsuario'] = $dadosDoUsuario->$dadosDoUsuario;
}
if (isset($_POST['submit'])) {
if (isset($_POST['email'], $_POST['senha'])) {
return true;
}
}
} catch (\PDOException $e) {
die("<h1>Não foi possivel estabelecer conexão," . " erro de código</h1>" . $e->getCode() . $e->getMessage());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment